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
Changes from 1 commit
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
3 changes: 2 additions & 1 deletion static_src/util/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export function validateString() {

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

Choose a reason for hiding this comment

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

We should move this outside the exported function, this will still re-parse the regex every time the function is called. Its not a big deal performance-wise but I think its good practice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@el-mapache Just moved up

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