views:

223

answers:

7

I'm new to Jquery and was wondering how to write an email validation using JQuery?

A: 

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);
}
Fabian
will this work if I place it in my JQuery script?
DuH
Yes it will, remember jQuery is still javascript :)
Fabian
A: 

learn how jquery works and then write it. Or google for a plugin that does what you want.

matpol
This is what Basil Fawlty would call 'stating the bleedin' obvious' ..?
5arx
A: 

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.

Mex
A: 

Have a look at the jQuery validation plugin:

http://docs.jquery.com/Plugins/Validation/Methods/email

Andrei Serdeliuc
A: 

We use this validation plugin for checking emails, plus a bunch of other stuff.

odavy
A: 

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.

Andrew Bashtannik
+2  A: 

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.

Nick Craver