uix_validations 0.4.8 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f42e5cab37cb240ef7553b7854285893179f6077cd6c79176eca95884f61176
|
4
|
+
data.tar.gz: 3508693ed965fa9a2807cc8c9fd769f510c345802fbab894b6b63f79efa86f05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11bd1069604223f419cea9bbae0a77cbc9223d493392e2dc06c97741815970820d6099251b5ec47fce5809d8589bedbf090e29bf2db68f94759ae72120cac5e9
|
7
|
+
data.tar.gz: 2c651e8b7fc01c5061c738ce91a67206947ea12fbd8ccd291caf983141f6624c323821af06fc0baab764d70fd365b0caec3abd7c32c2044ec5e25906a5f190a5
|
@@ -0,0 +1,106 @@
|
|
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
|
+
}
|
@@ -0,0 +1,23 @@
|
|
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
|
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
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Andrade
|
@@ -65,7 +65,9 @@ email:
|
|
65
65
|
executables: []
|
66
66
|
extensions: []
|
67
67
|
extra_rdoc_files: []
|
68
|
-
files:
|
68
|
+
files:
|
69
|
+
- vendor/assets/javascripts/uix_validations.js
|
70
|
+
- vendor/assets/stylesheets/uix_validations.scss
|
69
71
|
homepage: https://github.com/LucasAndrad/uix_validations
|
70
72
|
licenses:
|
71
73
|
- MIT
|