uix_validations 0.4.2 → 0.4.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +2 -4
- data/assets/javascripts/uix_validations.js +0 -106
- data/assets/stylesheets/uix_validations.scss +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea0861d8b9ce7a9148f85a95f4b2491ea331031e9de88b0279c9d7dfcb0b49a1
|
4
|
+
data.tar.gz: d66feb55b3b9f8576579cf13301daa3493c2a9e252bed7adabee053bcda98e99
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f18f0ffdc019ea426662f27412ecce41b2ed83b1ddeb96948673ec4cb16328c774c0ccbccedb70eed86278a0720e340a2eb0b7b58f71cd4003f0154457617147
|
7
|
+
data.tar.gz: 6dacfadd266f7761bf7e7f7e79b554688bbaee70f0c61ff7c6f3c426b8239fbb56ac95e1b13737988d38b540c607af67eddfed03d0b4b985f9471f45b1da9ed1
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: uix_validations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Andrade
|
@@ -65,9 +65,7 @@ email:
|
|
65
65
|
executables: []
|
66
66
|
extensions: []
|
67
67
|
extra_rdoc_files: []
|
68
|
-
files:
|
69
|
-
- assets/javascripts/uix_validations.js
|
70
|
-
- assets/stylesheets/uix_validations.scss
|
68
|
+
files: []
|
71
69
|
homepage: https://github.com/LucasAndrad/uix_validations
|
72
70
|
licenses:
|
73
71
|
- MIT
|
@@ -1,106 +0,0 @@
|
|
1
|
-
// Regex list
|
2
|
-
var numberPattern = /^[0-9]*$/;
|
3
|
-
var characterPattern = /^[a-zA-Z]*$/;
|
4
|
-
var nonDigitPattern = /^[^0-9]*$/;
|
5
|
-
|
6
|
-
// From https://stackoverflow.com/questions/46155/how-to-validate-an-email-address-in-javascript
|
7
|
-
var emailPattern = /\S+@\S+\.\S+/;
|
8
|
-
|
9
|
-
// From https://stackoverflow.com/questions/14850553/javascript-regex-for-password-containing-at-least-8-characters-1-number-1-uppe
|
10
|
-
var strongPasswordPattern = /^(?=.*\d)[0-9a-zA-Z]{8,}$/;
|
11
|
-
|
12
|
-
var veryStrongPasswordPattern = /^(?=.*[A-Z])(?=.*[!@#$&*.,_-])(?=.*[0-9])(?=.*[a-z]).{8,}$/
|
13
|
-
|
14
|
-
// Flow
|
15
|
-
// onClick -> set default
|
16
|
-
// checkinputValue->
|
17
|
-
// if (while is typing value is valid) { SET VALID }
|
18
|
-
// else { SET default }
|
19
|
-
// checkinputout->
|
20
|
-
// if (onFocusOut is valid) { SET VALID }
|
21
|
-
// else { SET INVALID }
|
22
|
-
|
23
|
-
// Generic functions
|
24
|
-
function validatePattern(fieldId, validId, regex) {
|
25
|
-
var field = document.querySelector(fieldId);
|
26
|
-
field.addEventListener("click", () => {
|
27
|
-
var valid = document.querySelector(validId);
|
28
|
-
setDefaultClass(valid);
|
29
|
-
checkInputValue(field, valid, regex)
|
30
|
-
checkInputOut(field, valid, regex);
|
31
|
-
});
|
32
|
-
}
|
33
|
-
function checkInputValue(field, valid, regex) {
|
34
|
-
field.addEventListener("keyup", () => {
|
35
|
-
switchClasses(field, valid, regex, ['uix-defaulf', 'uix-valid']);
|
36
|
-
// find way to get class type
|
37
|
-
});
|
38
|
-
}
|
39
|
-
function checkInputOut(field, valid, regex) {
|
40
|
-
field.addEventListener("focusout", () => {
|
41
|
-
switchClasses(field, valid, regex);
|
42
|
-
// find way to get class type
|
43
|
-
});
|
44
|
-
}
|
45
|
-
function setClasses(element, classIn) {
|
46
|
-
element.className = 'uix-validation ' + classIn;
|
47
|
-
}
|
48
|
-
function setDefaultClass(element) {
|
49
|
-
element.className = 'uix-validation uix-default';
|
50
|
-
element.style.visibility = 'inherit';
|
51
|
-
}
|
52
|
-
function switchClasses(field, valid, regex, classes = ['uix-invalid', 'uix-valid']) {
|
53
|
-
if(regex.test(field.value) && field.value != '') {
|
54
|
-
setClasses(valid, classes[1]);
|
55
|
-
}
|
56
|
-
else {
|
57
|
-
setClasses(valid, classes[0]);
|
58
|
-
}
|
59
|
-
}
|
60
|
-
|
61
|
-
// Specific functions
|
62
|
-
// Number
|
63
|
-
function validateNumber(fieldId, validId) {
|
64
|
-
validatePattern(fieldId, validId, numberPattern);
|
65
|
-
}
|
66
|
-
function validateNumberRange(fieldId, validId, range=[0,10]) {
|
67
|
-
var numberRangePattern = new RegExp(`^\\d{`+range[0]+`,`+range[1]+`}$`);
|
68
|
-
validatePattern(fieldId, validId, numberRangePattern);
|
69
|
-
}
|
70
|
-
// Character
|
71
|
-
function validateCharacter(fieldId, validId) {
|
72
|
-
validatePattern(fieldId, validId, characterPattern);
|
73
|
-
}
|
74
|
-
function validateCharacterLength(fieldId, validId, range=[0,10]) {
|
75
|
-
var characterRangePattern = new RegExp(`^\[a-zA-Z]{`+range[0]+`,`+range[1]+`}$`);
|
76
|
-
validatePattern(fieldId, validId, characterRangePattern);
|
77
|
-
}
|
78
|
-
// Non digit
|
79
|
-
function validateNonDigit(fieldId, validId) {
|
80
|
-
validatePattern(fieldId, validId, nonDigitPattern);
|
81
|
-
}
|
82
|
-
function validateNonDigitLength(fieldId, validId, range=[0,10]) {
|
83
|
-
var nonDigitRangePattern = new RegExp(`^\\D{`+range[0]+`,`+range[1]+`}$`);
|
84
|
-
validatePattern(fieldId, validId, nonDigitRangePattern);
|
85
|
-
}
|
86
|
-
// Email
|
87
|
-
function validateEmail(fieldId, validId) {
|
88
|
-
validatePattern(fieldId, validId, emailPattern);
|
89
|
-
}
|
90
|
-
// Range
|
91
|
-
function validateJustLength(fieldId, validId, range=[0,10]) {
|
92
|
-
var rangePattern = new RegExp(`^\\S{`+range[0]+`,`+range[1]+`}$`);
|
93
|
-
validatePattern(fieldId, validId, rangePattern);
|
94
|
-
}
|
95
|
-
// Any regex
|
96
|
-
function validateRegex(fieldId, validId, regex) {
|
97
|
-
validatePattern(fieldId, validId, regex);
|
98
|
-
}
|
99
|
-
// Strong Password
|
100
|
-
function validateStrongPassword(fieldId, validId) {
|
101
|
-
validatePattern(fieldId, validId, strongPasswordPattern);
|
102
|
-
}
|
103
|
-
// Very Strong Password
|
104
|
-
function validateVeryStrongPassword(fieldId, validId) {
|
105
|
-
validatePattern(fieldId, validId, veryStrongPasswordPattern);
|
106
|
-
}
|
@@ -1,23 +0,0 @@
|
|
1
|
-
.uix-validation {
|
2
|
-
padding: 1%;
|
3
|
-
font-size: 90%;
|
4
|
-
color: #232323;
|
5
|
-
width: 100%;
|
6
|
-
visibility: hidden;
|
7
|
-
}
|
8
|
-
.uix-default {
|
9
|
-
background: #ffffff;
|
10
|
-
}
|
11
|
-
.uix-valid {
|
12
|
-
color: #04a100;
|
13
|
-
font-weight: 400;
|
14
|
-
// background: #64e066;
|
15
|
-
|
16
|
-
}
|
17
|
-
.uix-invalid {
|
18
|
-
color: #cf0a0a;
|
19
|
-
font-weight: 400;
|
20
|
-
// background: #ff8484;
|
21
|
-
}
|
22
|
-
|
23
|
-
// old #5bff5e
|