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

Conversation

rememberlenny
Copy link
Contributor

No description provided.

@rememberlenny rememberlenny force-pushed the lkb-email_validation_rfc822 branch from aaf28ee to d80f623 Compare June 23, 2017 17:37
@rememberlenny
Copy link
Contributor Author

Fixed the tests here. Ready for review.

@@ -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!

@rememberlenny
Copy link
Contributor Author

@el-mapache Great point. I just stored this as a variable.

@@ -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

Copy link
Contributor

@el-mapache el-mapache left a comment

Choose a reason for hiding this comment

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

LGTM!

@rememberlenny rememberlenny merged commit bcb8b25 into master Jun 23, 2017
@rememberlenny rememberlenny deleted the lkb-email_validation_rfc822 branch June 23, 2017 20:40
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants