Results 1 to 2 of 2

Thread: checkEmail()

  1. #1
    Join Date
    May 2007
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default checkEmail()

    i used bellow code for email address validation, but it doesn't work?

    <script language="javascript">
    // email
    function checkEmail (strng) {
    var error="";
    if (strng == "") {
    error = "You didn't enter an email address.\n";
    }

    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) {
    error = "Please enter a valid email address.\n";
    }
    else {
    //test email for illegal characters
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
    if (strng.match(illegalChars)) {
    error = "The email address contains illegal characters.\n";
    }
    }
    return error;
    }
    </script>

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Works fine here, but it is incomplete in that it won't do much that one would notice. If you were to change it to:

    Code:
    function checkEmail (strng) {
    var error="";
    if (strng == "") {
    error = "You didn't enter an email address.\n";
    }
    
    var emailFilter=/^.+@.+\..{2,3}$/;
    if (!(emailFilter.test(strng))) { 
    error = "Please enter a valid email address.\n";
    }
    else {
    //test email for illegal characters
    var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/
    if (strng.match(illegalChars)) {
    error = "The email address contains illegal characters.\n";
    }
    }
    if (error)
    alert(error); 
    }
    Then you would actually have something.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •