Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Created February 8, 2012 05:37
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elijahmanor/1765839 to your computer and use it in GitHub Desktop.
Save elijahmanor/1765839 to your computer and use it in GitHub Desktop.
Regular Expressions in CoffeeScript
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 "john.smith@gmail.com".match emailPattern
console.log "E-mail is valid"
else
console.log "E-mail is invalid"
var emailPattern = /^([\w.-]+)@([\w.-]+)\.([a-zA-Z.]{2,6})$/i;
if ( "john.smith@gmail.com".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