Problem in email validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kavithadevan
    New Member
    • Jul 2007
    • 23

    Problem in email validation

    Hi,
    I am trying to validate my form email field if i gave condition for empty field its working then again i checked whether the email id is valid one or not but its working but if i give valid id that time also it displays the alert box only

    can anyone tell me wat problem in my code
    here is the code
    [code=javascript]

    function validate()
    {
    var emailid=documen t.getElementByI d('email')
    var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1, 3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
    if(emailid.valu e.length==0)
    {
    alert("Must to enter email id");
    emailid.focus()
    return false;
    }
    if (!emailid.match (emailPat)) {
    alert("Your email address seems incorrect. Please try again (check the '@' and '.'s in the email address)");
    return false;
    }
    }
    </script>
    [/code]
  • vee10
    New Member
    • Oct 2006
    • 141

    #2
    Hi ,

    the problem in ur code is at the last if conditon

    if (!emailid.match (emailPat))

    it should be

    if (!(emailid.valu e.match(emailPa t)))

    regards


    Originally posted by kavithadevan
    Hi,
    I am trying to validate my form email field if i gave condition for empty field its working then again i checked whether the email id is valid one or not but its working but if i give valid id that time also it displays the alert box only

    can anyone tell me wat problem in my code
    here is the code
    [code=javascript]

    function validate()
    {
    var emailid=documen t.getElementByI d('email')
    var emailPat = /^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1, 3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/;
    if(emailid.valu e.length==0)
    {
    alert("Must to enter email id");
    emailid.focus()
    return false;
    }
    if (!emailid.match (emailPat)) {
    alert("Your email address seems incorrect. Please try again (check the '@' and '.'s in the email address)");
    return false;
    }
    }
    </script>
    [/code]

    Comment

    • kavithadevan
      New Member
      • Jul 2007
      • 23

      #3
      Hi,
      Mycode is working now
      thanks

      Originally posted by vee10
      Hi ,

      the problem in ur code is at the last if conditon

      if (!emailid.match (emailPat))

      it should be

      if (!(emailid.valu e.match(emailPa t)))

      regards

      Comment

      Working...