Posted By

chrisaiv on 02/03/09


Tagged

regexp as3


Versions (?)

Who likes this?

8 people have marked this snippet as a favorite

enajenkins
vip4lyf
zimmen
orazal
edsonpavoni
quan
tspitzr
onemanstudio


AS3: Regular Expression Helpers


 / Published in: ActionScript 3
 

Here are some easy functions to validate E-mail and Phone Numbers

  1. // REGEX for email validation
  2. function validateEmail(email:String):Boolean {
  3. var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
  4. return ! emailExpression.test(email);
  5. }
  6. // REGEX for phone validation
  7. function validatePhone(phone:String):Boolean {
  8. var emailExpression:RegExp = /^((\+\d{1,3}(-| )?\(?\d\)?(-| )?\d{1,3})|(\(?\d{2,3}\)?))(-| )?(\d{3,4})(-| )?(\d{4})(( x| ext)\d{1,5}){0,1}$/i;
  9. return ! emailExpression.test(phone);
  10. }

Report this snippet  

You need to login to post a comment.