From 53e26cbebbb0c00c5d2d0faaeb40bd2f42e18336 Mon Sep 17 00:00:00 2001 From: Dominik Guzei Date: Thu, 6 Jun 2019 12:39:36 +0200 Subject: Use same email validation as on the api --- package-lock.json | 7 ++++++- package.json | 1 + src/helpers/validation-helpers.js | 10 ++-------- .../messages/src/helpers/validation-helpers.json | 20 ++++++++++---------- 4 files changed, 19 insertions(+), 19 deletions(-) diff --git a/package-lock.json b/package-lock.json index fc328c4b4..a00e68da2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "franz", - "version": "5.0.1", + "version": "5.1.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -20034,6 +20034,11 @@ "builtins": "^1.0.3" } }, + "validator": { + "version": "11.0.0", + "resolved": "https://registry.npmjs.org/validator/-/validator-11.0.0.tgz", + "integrity": "sha512-+wnGLYqaKV2++nUv60uGzUJyJQwYVOin6pn1tgEiFCeCQO60yeu3Og9/yPccbBX574kxIcEJicogkzx6s6eyag==" + }, "value-or-function": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/value-or-function/-/value-or-function-3.0.0.tgz", diff --git a/package.json b/package.json index c1a8c310f..bfc06c005 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,7 @@ "smoothscroll-polyfill": "^0.3.4", "tar": "^4.0.2", "uuid": "^3.0.1", + "validator": "11.0.0", "ws": "6.2.1" }, "devDependencies": { diff --git a/src/helpers/validation-helpers.js b/src/helpers/validation-helpers.js index 2f762437d..ab2376b1b 100644 --- a/src/helpers/validation-helpers.js +++ b/src/helpers/validation-helpers.js @@ -1,4 +1,5 @@ import { defineMessages } from 'react-intl'; +import isEmail from 'validator/lib/isEmail'; const messages = defineMessages({ required: { @@ -30,14 +31,7 @@ export function required({ field }) { export function email({ field }) { const value = field.value.trim(); - let isValid = false; - - if (value !== '') { - isValid = Boolean(value.match(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,63}/i)); - } else { - isValid = true; - } - + const isValid = isEmail(value); return [isValid, window.franz.intl.formatMessage(messages.email, { field: field.label })]; } diff --git a/src/i18n/messages/src/helpers/validation-helpers.json b/src/i18n/messages/src/helpers/validation-helpers.json index 86bfe1500..6be1d33e9 100644 --- a/src/i18n/messages/src/helpers/validation-helpers.json +++ b/src/i18n/messages/src/helpers/validation-helpers.json @@ -4,11 +4,11 @@ "defaultMessage": "!!!Field is required", "file": "src/helpers/validation-helpers.js", "start": { - "line": 4, + "line": 5, "column": 12 }, "end": { - "line": 7, + "line": 8, "column": 3 } }, @@ -17,11 +17,11 @@ "defaultMessage": "!!!Email not valid", "file": "src/helpers/validation-helpers.js", "start": { - "line": 8, + "line": 9, "column": 9 }, "end": { - "line": 11, + "line": 12, "column": 3 } }, @@ -30,11 +30,11 @@ "defaultMessage": "!!!Not a valid URL", "file": "src/helpers/validation-helpers.js", "start": { - "line": 12, + "line": 13, "column": 7 }, "end": { - "line": 15, + "line": 16, "column": 3 } }, @@ -43,11 +43,11 @@ "defaultMessage": "!!!Too few characters", "file": "src/helpers/validation-helpers.js", "start": { - "line": 16, + "line": 17, "column": 13 }, "end": { - "line": 19, + "line": 20, "column": 3 } }, @@ -56,11 +56,11 @@ "defaultMessage": "!!!At least one is required", "file": "src/helpers/validation-helpers.js", "start": { - "line": 20, + "line": 21, "column": 15 }, "end": { - "line": 23, + "line": 24, "column": 3 } } -- cgit v1.2.3-54-g00ecf