Created
February 8, 2012 05:37
-
-
Save elijahmanor/1765839 to your computer and use it in GitHub Desktop.
Regular Expressions in CoffeeScript
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
emailPattern = /// ^ #begin of line | |
([\w.-]+) #one or more letters, numbers, _ . or - | |
@ #followed by an @ sign | |
([\w.-]+) #then one or more letters, numbers, _ . or - | |
\. #followed by a period | |
([a-zA-Z.]{2,6}) #followed by 2 to 6 letters or periods | |
$ ///i #end of line and ignore case | |
if "[email protected]".match emailPattern | |
console.log "E-mail is valid" | |
else | |
console.log "E-mail is invalid" |
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
var emailPattern = /^([\w.-]+)@([\w.-]+)\.([a-zA-Z.]{2,6})$/i; | |
if ( "[email protected]".match( emailPattern ) ) { | |
console.log( "E-mail is valid" ); | |
} else { | |
console.log( "E-mail is invalid" ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment