Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
Last active January 4, 2016 04:09
Show Gist options
  • Select an option

  • Save ChrisLTD/8566361 to your computer and use it in GitHub Desktop.

Select an option

Save ChrisLTD/8566361 to your computer and use it in GitHub Desktop.
Regex for minimally testing valid email addresses. Looks for some characters, @ symbol, some characters, a period, then some more characters.
var regex = /^.+@.+\..+$/;
var tests = Array( 'test@test.com', 'testATtest.com', 'test@testDOTcom',
'test.period@test.com', 'test+period@test.com', 'test@test.co.uk');
for(var i = 0; i < tests.length; i++){
var result = regex.exec( tests[i] );
console.log('Testing: ' + tests[i]);
if( result ){
console.log('match found\n');
} else {
console.log('no matches\n');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment