Results 1 to 2 of 2

Thread: Help with a this e-mail validation function

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

    Default Help with a this e-mail validation function

    It works when I don't input a correct e-mail format, but when I do, it won't let me go to the next field, it focuses on that field and selects it. What am i missing?

    Thanks!

    function checkEmail(field, fieldname){
    var x = field.value;
    var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
    if(field.value.length > 0 ) {
    if (filter.test(x));
    else alert('Oops! This doesn\'t appear to be a valid e-mail address.');
    field.focus();
    field.select();
    }
    }

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Why wouldn't it?
    You've told it to.

    I think you mean to say:
    Code:
    function checkEmail(field, fieldname) {
      var x = field.value,
        filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
      if(field.value.length > 0 && !filter.test(x)) {
        alert('Oops! This doesn\'t appear to be a valid e-mail address.');
        field.focus();
        field.select();
      }
    }
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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
  •