@gudhub/ssg-web-components-library 1.0.124 → 1.0.125
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -20,11 +20,15 @@ export const checkInputsValidations = (inputs) => {
|
|
|
20
20
|
return result;
|
|
21
21
|
};
|
|
22
22
|
|
|
23
|
+
const isEmptyAndOptional = (input) => {
|
|
24
|
+
const value = input.value.trim();
|
|
25
|
+
return value === '' && !input.hasAttribute('required');
|
|
26
|
+
};
|
|
23
27
|
|
|
24
28
|
const emailValidation = (input) => {
|
|
25
29
|
const regex = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
|
|
26
30
|
|
|
27
|
-
let isValid = regex.test(input.value);
|
|
31
|
+
let isValid = isEmptyAndOptional(input) || regex.test(input.value);
|
|
28
32
|
|
|
29
33
|
if (!isValid) {
|
|
30
34
|
input.classList.add('error');
|
|
@@ -38,11 +42,9 @@ const emailValidation = (input) => {
|
|
|
38
42
|
};
|
|
39
43
|
|
|
40
44
|
const phoneValidation = (input) => {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const regex = /^\+?\d+$/; // We can write only numbers without special symbols besides "+" sign
|
|
45
|
+
const regex = /^\+?\d+$/;
|
|
44
46
|
|
|
45
|
-
let isValid = regex.test(input.value);
|
|
47
|
+
let isValid = isEmptyAndOptional(input) || regex.test(input.value);
|
|
46
48
|
|
|
47
49
|
if (!isValid) {
|
|
48
50
|
input.classList.add('error');
|