I\'m new to jQuery and was wondering how to use it to validate email addresses.
I would recommend Verimail.js, it also has a JQuery plugin.
Why? Verimail supports the following:
So besides validation, Verimail.js also gives you suggestions. So if you type an email with the wrong TLD or domain that is very similar to a common email domain (hotmail.com, gmail.com, etc), it can detect this and suggest a correction.
Examples:
And so on..
To use it with jQuery, just include verimail.jquery.js on your site and run the function below:
$("input#email-address").verimail({
messageElement: "p#status-message"
});
The message element is an element in which a message will be shown. This can be everything from "Your email is invalid" to "Did you mean ...?".
If you have a form and want to restrict it so that it cannot be submitted unless the email is valid, then you can check the status using the getVerimailStatus-function as shown below:
if($("input#email-address").getVerimailStatus() < 0){
// Invalid
}else{
// Valid
}
This function returns an integer status code according to the object Comfirm.AlphaMail.Verimail.Status. But the general rule of thumb is that any codes below 0 is codes indicating errors.