Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Email validation with javascript

    This are my codes..

    var add = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
    var email = form.txtEmail.value;
    if (add.test(email) = false)
    {
    alert("Please enter a valid email.");
    return false;
    }
    return true;
    }


    bt it wun work.. pls help..

  • #2
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    You might have better luck on the client side JavaScript programming forum. As this is the server side (PHP) scripting forum.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Yes indeed. Moving from PHP to Javascript.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 
    Been gone for a few months, and haven't programmed in that long of a time. Meh, I'll wing it ;)

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,080
    Thanks
    203
    Thanked 2,542 Times in 2,520 Posts
    Here you are:-

    Code:
    <form name= "form1">
    <input type = "text" name = "txtEmail" onblur ="chkemail(this)">
    </form>
    
    <script type = "text/javascript">
    
    function chkemail(which) {
    var email = which.value;
    if (!/^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/.test(email)) {
    alert("Please enter a valid email address!");
    which.value = "";
    myfield = which;  // note myfield must be a global variable
    setTimeout('myfield.focus();myfield.select();' , 10);  // to overcome a bug in Firefox
    return false;
    }
    return true;
    }
    
    </script>

    Quizmaster: When counting down, what whole number follows 37?
    Contestant: er, 19.


  •  

    Posting Permissions

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