co.validation 2.2.1 → 2.2.2
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.
|
@@ -521,6 +521,12 @@ describe('createValidation', () => {
|
|
|
521
521
|
data: undefined,
|
|
522
522
|
errors: ['Invalid email format']
|
|
523
523
|
});
|
|
524
|
+
expect((0, _.createValidation)({
|
|
525
|
+
type: 'email'
|
|
526
|
+
})('email.@mail.com')).toEqual({
|
|
527
|
+
data: undefined,
|
|
528
|
+
errors: ['Invalid email format']
|
|
529
|
+
});
|
|
524
530
|
});
|
|
525
531
|
it('supports alphanumeric', () => {
|
|
526
532
|
expect((0, _.createValidation)({
|
package/lib/validators.js
CHANGED
|
@@ -102,10 +102,11 @@ const maxValue = ({
|
|
|
102
102
|
};
|
|
103
103
|
|
|
104
104
|
exports.maxValue = maxValue;
|
|
105
|
+
const emailRegex = /^[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/i;
|
|
105
106
|
|
|
106
107
|
const email = ({
|
|
107
108
|
getMessage
|
|
108
|
-
}) => value => value &&
|
|
109
|
+
}) => value => value && !emailRegex.test(value) ? {
|
|
109
110
|
errors: (0, _messageProcessor.default)(getMessage, '##email')
|
|
110
111
|
} : {
|
|
111
112
|
data: value
|