Skip to content
This repository has been archived by the owner on May 19, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1135 from 18F/lkb-email_validation_rfc822
Browse files Browse the repository at this point in the history
Correct validator to use rfc822 email validation
  • Loading branch information
rememberlenny authored Jun 23, 2017
2 parents d2fca51 + 41addee commit bcb8b25
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 12 additions & 2 deletions static_src/test/unit/util/validators.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,23 @@ describe('validateEmail', function () {
});

it('fails for none emails string@', function () {
const result = validator('domain@place');
const result = validator('domain@');
expect(result).toEqual({ message: 'The value entered is not a valid e-mail address' });
});

it('fails for none emails string@domain.', function () {
const result = validator('domain@domain.');
expect(result).toEqual({ message: 'The value entered is not a valid e-mail address' });
});

it('fails for none emails string@string', function () {
const result = validator('domain@place');
expect(result).toEqual({ message: 'The value entered is not a valid e-mail address' });
expect(result).toEqual(null);
});

it('fails for none emails string@string.com.co', function () {
const result = validator('domain@place');
expect(result).toEqual(null);
});

it('succeeds for email', function () {
Expand Down
4 changes: 3 additions & 1 deletion static_src/util/validators.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;

export function validateInteger(options) {
const { max, min } = options || {};
return function _validateInteger(text) {
Expand Down Expand Up @@ -41,7 +43,7 @@ export function validateString() {

export function validateEmail() {
return function _validateEmail(value, name) {
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value))) {
if (!(EMAIL_REGEX).test(value)) {
const nameString = (name ? `in ${name} ` : '');
return {
message: `The value entered ${nameString}is not a valid e-mail address`
Expand Down

0 comments on commit bcb8b25

Please sign in to comment.