Posted By


dbugger on 03/29/11

Tagged


Statistics


Viewed 740 times
Favorited by 2 user(s)

Email validation


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function check_email_address($email) {
  2. if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) {
  3. return false;
  4. }
  5.  
  6. $email_array = explode("@", $email);
  7. $local_array = explode(".", $email_array[0]);
  8. for ($i = 0; $i < sizeof($local_array); $i++) {
  9. if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&�'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",$local_array[$i])) {
  10. return false;
  11. }
  12. }
  13.  
  14. if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
  15. $domain_array = explode(".", $email_array[1]);
  16.  
  17. if (sizeof($domain_array) < 2) {
  18. return false;
  19. }
  20. for ($i = 0; $i < sizeof($domain_array); $i++) {
  21. if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|�([A-Za-z0-9]+))$",$domain_array[$i])) {
  22. return false;
  23. }
  24. }
  25. }
  26. return true;
  27. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.