Monday, November 12, 2012

HTML Form Validation via Javascript

I want to keep viewers from entering words like \”fssadf\”, and force them to enter a valid email which must contain the \”@\” in the middle and \”.\” to prevent spam and injection.


I also want the form to display an error message that says \”change the email field to the correct email\”


I use js_function.js which contain this:



function validEmail()
{
var reg = /^([A-Za-z0-9_\\-\\.])+\\@([A-Za-z0-9_\\-\\.])+\\.([A-Za-z]{2,4})$/;
var email_address = $(\"#email\").val();
if(reg.test(email_address) == false)
return false;
else
return true;
}


but it does not prevent the viewer from sending me \”sfdasfd\” instead of a valid email.


What can I do to achieve the above?


check out the files below:

http://www.mediafire.com/?kx5bvttc0s2fbrs


thanks,

rami






Rating: 5 out of 5 based on 4 ratings



The post HTML Form Validation via Javascript appeared first on Javascript ASK.






via Javascript ASK http://javascriptask.phpfogapp.com/html-form-validation-via-javascript.html

No comments:

Post a Comment