Skip to content

Commit a575b87

Browse files
abdulbasithqbabdulbasithaadids1221
authored
fix: Allow empty strings for email and number validation in validators.ts (#2811)
* fix: Allow empty strings for email & number validation * revert: RegEx decimal * Update src/components/textField/validators.ts Co-authored-by: Adi Mordo <[email protected]> * Update src/components/textField/validators.ts Co-authored-by: Adi Mordo <[email protected]> * added optionalEmail to validators.ts --------- Co-authored-by: abdulbasitha <[email protected]> Co-authored-by: Adi Mordo <[email protected]>
1 parent 5049b12 commit a575b87

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/components/textField/validators.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ const priceRegEx = /^[0-9]{1,9}([.][0-9]{1,2})?$/;
99
const validators = {
1010
required: (value = '') => !_.isEmpty(value),
1111
email: (value = '') => new EmailValidator().isValid(value),
12+
optionalEmail : (value = '') => {
13+
// Allow empty strings
14+
if (_.isEmpty(value)) {
15+
return true;
16+
}
17+
return new EmailValidator().isValid(value);
18+
},
1219
url: (value = '') => urlRegEx.test(value),
1320
number: (value = '') => integerRegEx.test(value) || decimalNumberRegEx.test(value),
1421
price: (value = '') => priceRegEx.test(value)

0 commit comments

Comments
 (0)