Created
May 11, 2016 18:01
-
-
Save Ch4s3/869f4d1fe82984e8d5ef0733ab0d1798 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
isValidEmail(e) { | |
/* | |
* This regex SHOULD capture 99% of valid e-mails, but it is from StackOverflow | |
* so I can't garuntee that. It works well in tests, but if it fails, lets switch | |
* to a simple /@/ or use the MailGun API. | |
*/ | |
const emailRegex = /[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?/ | |
const emailFieldValue = e.target.value | |
if (emailFieldValue.length == 0) { | |
this.setState({ validEmail: null }) | |
} else { | |
const valid = emailRegex.test(emailFieldValue); | |
if (valid == true) { | |
this.setState({ validEmail: true }) | |
} else { | |
this.setState({ validEmail: false }) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment