AS3 Email Validation Code Snippets - Regular Expression

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Regular expressions are something that were introduced in AS3 with a sigh of relief from all flash developers. Yay

Below is a code snippet posted by senocular at kriupa

function isValidEmail(email:String):Boolean {    
var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
 
return emailExpression.test(email);
 
}
 
//...
 
trace(isValidEmail("senocular@example.com")); // true
 
trace(isValidEmail("@example.com")); // false
 
trace(isValidEmail("senocular@example")); // false
 
trace(isValidEmail("seno\\cular@example.com")); // false

Its a beautiful thing.



3 Responses to “AS3 Email Validation Code Snippets - Regular Expression”

  1. [...] I Have just posted up a code snippet that validates general email addresses in AS2. [Update] - Click here for the AS3 Email Validation Code [...]

  2. [...] as the first. I have added a new email validation process which is new to AS3(regexp) Thanks to flashcs.org for the script. I have also added a drop down menu with the list of countries being pulled from an [...]

  3. [...] I Have just posted up a code snippet that validates general email addresses in AS2. [Update] - Click here for the AS3 Email Validation Code [...]

Leave a Reply

Close
E-mail It