Posted By

orazal on 08/22/07


Tagged

actionscript validation


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

n00ge
chrisaiv
eorwoll
mrjthethird
LarryStreeter


validateEmail


 / Published in: ActionScript
 

  1. /**
  2.  * Checks if an email is written correctly
  3.  *
  4.  * @param email The email we're checking
  5.  * @return A result boolean
  6.  */
  7. function validateEmail(email:String):Boolean {
  8. //check for @
  9. if (email.indexOf("@")>0) {
  10. // strip blank spaces at end
  11. if (email.indexOf(" ")>0) {
  12. email = email.substr(0, email.indexOf(" "));
  13. }
  14. if (email.indexOf(" ")>0) {
  15. // Has blank spaces in the middle.
  16. return false;
  17. } else {
  18. // check for the dot
  19. var ext = email.substr(email.lastIndexOf(".")+1, email.length);
  20. if (ext.length>1 && ext.length<4) {
  21. // Passed
  22. return true;
  23. } else {
  24. // No dot found
  25. return false;
  26. }
  27. }
  28. } else {
  29. // No @ found
  30. return false;
  31. }
  32. }

Report this snippet  

You need to login to post a comment.