AS3: Regular Expression Helpers


/ Published in: ActionScript 3
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.