Skip to content

Commit

Permalink
fix(App): Improved email validation /cc @Snuggle
Browse files Browse the repository at this point in the history
  • Loading branch information
DominikGuzei authored Jun 6, 2019
2 parents 02f6c5f + e033131 commit dd8ddcc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 29 deletions.
7 changes: 6 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
10 changes: 2 additions & 8 deletions src/helpers/validation-helpers.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineMessages } from 'react-intl';
import isEmail from 'validator/lib/isEmail';

const messages = defineMessages({
required: {
Expand Down Expand Up @@ -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 })];
}

Expand Down
20 changes: 10 additions & 10 deletions src/i18n/locales/defaultMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -3759,65 +3759,65 @@
"defaultMessage": "!!!Field is required",
"end": {
"column": 3,
"line": 7
"line": 8
},
"file": "src/helpers/validation-helpers.js",
"id": "validation.required",
"start": {
"column": 12,
"line": 4
"line": 5
}
},
{
"defaultMessage": "!!!Email not valid",
"end": {
"column": 3,
"line": 11
"line": 12
},
"file": "src/helpers/validation-helpers.js",
"id": "validation.email",
"start": {
"column": 9,
"line": 8
"line": 9
}
},
{
"defaultMessage": "!!!Not a valid URL",
"end": {
"column": 3,
"line": 15
"line": 16
},
"file": "src/helpers/validation-helpers.js",
"id": "validation.url",
"start": {
"column": 7,
"line": 12
"line": 13
}
},
{
"defaultMessage": "!!!Too few characters",
"end": {
"column": 3,
"line": 19
"line": 20
},
"file": "src/helpers/validation-helpers.js",
"id": "validation.minLength",
"start": {
"column": 13,
"line": 16
"line": 17
}
},
{
"defaultMessage": "!!!At least one is required",
"end": {
"column": 3,
"line": 23
"line": 24
},
"file": "src/helpers/validation-helpers.js",
"id": "validation.oneRequired",
"start": {
"column": 15,
"line": 20
"line": 21
}
}
],
Expand Down
20 changes: 10 additions & 10 deletions src/i18n/messages/src/helpers/validation-helpers.json
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
},
Expand All @@ -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
}
},
Expand All @@ -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
}
},
Expand All @@ -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
}
},
Expand All @@ -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
}
}
Expand Down

0 comments on commit dd8ddcc

Please sign in to comment.