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 PatelRank #292 · 8.6K reputationPosted Dec 6, 2009, 3:51 AM EST
if my answer helps you then check "Do you like this answer" check box please :)
function validateEmail() { var emailRegEx = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/; if (document.getElementById('Text1').value.match(emailRegEx)) { alert('Correct!!'); } else { alert('Wrong Email !!'); } }Ravi PanaraRank #7,641 · 237 reputationPosted Feb 25, 2010, 4:31 AM EST
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');
}