Hi...all
In this post we are discussing about javascript validationof email.
ok.first of all check these things
the name of your form form1 for example
the name of your field email for example
the name of yout id email for example
now javascript means client side validation that you can perform by onclick or onsubmit event..
Suppose we use onclick event
in your html page code is
input type="botton" onclick="validate()"
Now we have to create javascript function
function validate()
{
// we can use name or email
1 if(document.form1.email.value!="")
{
2 if(document.form1.email.value.search(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) == -1)
{
3 alert("Invalid Email Address");
4 document.form1.email.focus();
5 return false;
}
}
Execution :
1 line checks the value of email field is blank or not
2 line if the condition of first line satisfy at that time line 2 checks some of content of that vlaue is proper or not in short it checks it is valid or not
3 line popup the message
4 that send the focus of your cursor on email field
5 it stop the execution
}
Comments
Post a Comment