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

Correct validator to use rfc822 email validation #1135

Merged
merged 4 commits into from
Jun 23, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 [email protected]', function () {
const result = validator('domain@place');
expect(result).toEqual(null);
});

it('succeeds for email', function () {
Expand Down
2 changes: 1 addition & 1 deletion static_src/util/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export function validateString() {

export function validateEmail() {
return function _validateEmail(value, name) {
if (!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(value))) {
if (!(/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/).test(value)) {
Copy link
Contributor

@el-mapache el-mapache Jun 23, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might make the regex itself a const outside the function so we don't have to create it each time we call validateEmail. As a bonus it can replace the regexp literal with a readable name!

const nameString = (name ? `in ${name} ` : '');
return {
message: `The value entered ${nameString}is not a valid e-mail address`
Expand Down