Posted By

rwitten on 03/01/08


Tagged

regex


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

gismo
Akuma99
outbox
THEPWN3R
allnatural


Simple RegEx


 / Published in: ActionScript 3
 

Pulled from Adobe Docs

  1. private function validateEmail(str:String):Boolean {
  2. var pattern:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
  3. var result:Object = pattern.exec(str);
  4. if(result == null) {
  5. return false;
  6. }
  7. return true;
  8. }
  9. private function validatePhoneNumber(str:String):Boolean {
  10. var pattern:RegExp = /^\d{3}-\d{3}-\d{4}$/;
  11. var result:Object = pattern.exec(str);
  12. if(result == null) {
  13. return false;
  14. }
  15. return true;
  16. }
  17.  
  18. function isValidEmail(email:String):Boolean {
  19. var emailExpression:RegExp = /^[a-z][\w.-]+@\w[\w.-]+\.[\w.-]*[a-z][a-z]$/i;
  20. return emailExpression.test(email);
  21. }
  22. //...
  23. trace(isValidEmail("[email protected]")); // true
  24. trace(isValidEmail("@example.com")); // false
  25. trace(isValidEmail("senocular@example")); // false
  26. trace(isValidEmail("seno\\[email protected]")); // false

Report this snippet  

You need to login to post a comment.