www.webdeveloper.com
Results 1 to 11 of 11

Thread: email validation help

  1. #1
    Join Date
    Dec 2011
    Posts
    79

    email validation help

    Hi. added a email valdation check to my webpage. but for some reason it always says the email is invalid. please help


    Code:
    function checkEmail() {
    var email = document.mail.email;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email.value)) {
    alert('Please provide a valid email address');
    email.focus;
    return false;
    }
    
    else return true
    }

  2. #2
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    the function looks okay, so it's probably a larger issue. you might want to show your entire script block and the html for your email input

  3. #3
    Join Date
    Dec 2011
    Posts
    79
    Code:
    <input type="text" id='email' name='email' type="text" size="33" onchange="checkEmail()">
    i cant really post the whole of the script as its way over the char limit

  4. #4
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    have you tried:

    Code:
    <input type="text" id='email' name='email' type="text" size="33" onchange="return checkEmail()">

  5. #5
    Join Date
    Dec 2011
    Posts
    79
    Quote Originally Posted by DanInMA View Post
    the function looks okay, so it's probably a larger issue. you might want to show your entire script block and the html for your email input

    ive just set up a new page with just that script and it works fine, it must be something else in the script ive messed up. thanks for helping

  6. #6
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    Quote Originally Posted by chrisboots View Post
    ive just set up a new page with just that script and it works fine, it must be something else in the script ive messed up. thanks for helping
    ah okie. probably a rogue { or } somewhere.

    you cna do several things. use jsbeautifier.org on your script ( alos helps find unclosed brackets etc.., or load your test page in firefox with firebug installed to check for possible console errors

    you could also try jslint online or jshint.org

  7. #7
    Join Date
    Dec 2011
    Posts
    79
    Quote Originally Posted by DanInMA View Post
    ah okie. probably a rogue { or } somewhere.

    you cna do several things. use jsbeautifier.org on your script ( alos helps find unclosed brackets etc.., or load your test page in firefox with firebug installed to check for possible console errors

    you could also try jslint online or jshint.org
    I have tried EVERYTHING and i still cannot get this damn thing to work, any more ideas ?

  8. #8
    Join Date
    Dec 2011
    Posts
    79
    Quote Originally Posted by DanInMA View Post
    ah okie. probably a rogue { or } somewhere.

    you cna do several things. use jsbeautifier.org on your script ( alos helps find unclosed brackets etc.., or load your test page in firefox with firebug installed to check for possible console errors

    you could also try jslint online or jshint.org

    nevermind, im being stupid!. I had to input id's as email, which obviously broke the code

  9. #9
    Join Date
    Apr 2010
    Location
    Salem,Ma
    Posts
    623
    oh also try editing your js using notepadd++ or something imilar. makes it really easy to find unbalanced brackets etc

  10. #10
    Join Date
    Jun 2011
    Posts
    141
    I have just tried this script but my "name" for my email input is emailAD so which parts of the following do I change from email to emailAD because I don't think it is all of them, is it:

    Code:
    function checkEmail() {
    var email = document.mail.email;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email.value)) {
    alert('Please provide a valid email address');
    email.focus;
    return false;
    }
    
    else return true
    }

  11. #11
    Join Date
    Dec 2011
    Posts
    79
    Quote Originally Posted by djadejones View Post
    I have just tried this script but my "name" for my email input is emailAD so which parts of the following do I change from email to emailAD because I don't think it is all of them, is it:

    Code:
    function checkEmail() {
    var email = document.mail.email;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if (!filter.test(email.value)) {
    alert('Please provide a valid email address');
    email.focus;
    return false;
    }
    
    else return true
    }
    Change the bit in bold, to document.getElementById('emailAD')

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles