Hello.
i am facing a problem in form validation.
i designed few field user name/ password /confirm password /, age and email address.
i create a function in java script. all text validation is working but email address making problem, i used regex but nothing happen, here is my code
if(EmailId=='')
{
alert("Enter Email id");
document.getElementById("txtEmail").focus();
return false;
}
//its working if i leave blank its not allowing but when i type wrong or right email address its say enter correct email
else
{
if(!EmailId.match('/^(\".*\"|[A-Za-z]\w*)@(\[\d{1,3}(\.\d{1,3}){3}]|[A-Za-z]\w*(\.[A-Za-z]\w*)+)$/'))
{
alert("Enter correct Email.");
document.getElementById("txtEmail").focus();
return false;
}
}
on run time its says enter correct email.
so could you please tell me where i m making a mistake.
and also tell me how can i clear text field when error msg occur nd after clicking ok focus set on tht field
if i m not clear in my query. tell me , i m pooped out
Thanks
Regards
Rashid
Loading
Kirtan PatelPosted Dec 6, 2009, 8:51 AM
if my answer helps you then check "Do you like this answer" check box please :)
Ravi PanaraPosted Feb 25, 2010, 9:31 AM
var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
var emailaddress = document.getElementById('<%=txtemail.ClientID %>').value;
if(reg.test(emailaddress) == false)
{
alert('Invalid Email Address');
return false;
}
else
{
alert('Valid Email Address');
}