I'm new to Jquery and was wondering how to write an email validation using JQuery?
You can use regular old javascript for that:
function IsEmail(email) {
var regex = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
}
learn how jquery works and then write it. Or google for a plugin that does what you want.
I am sorry to say google it http://www.reynoldsftw.com/2009/03/live-email-validation-with-jquery/
I believe that http://docs.jquery.com/Plugins/Validation this plugin make email validation easy as well as other form fields you might want to check.
We use this validation plugin for checking emails, plus a bunch of other stuff.
Look at http://bassistance.de/jquery-plugins/jquery-plugin-validation/. It is nice jQuery plugin, which allow to build powerfull validation system for forms. There are some usefull samples here. So, email field validation in form will look so:
$("#myform").validate({
rules: {
field: {
required: true,
email: true
}
}
});
See Email method documentation for details and samples.
I would use the jQuery validation plugin for a few reasons.
You validated, ok great, now what? You need to display the error, handle erasing it when it is valid, displaying how many errors total perhaps? There are lots of things it can handle for you, no need to re-invent the wheel.
Also, another huge benefit is it's hosted on a CDN, the current version at the time of this answer can be found here: http://www.asp.net/ajaxLibrary/CDNjQueryValidate16.ashx This means faster load times for the client.