I'm new to jQuery and was wondering how to use it to validate email addresses.
相关问题
- How to fix IE ClearType + jQuery opacity problem i
- jQuery add and remove delay
- Include empty value fields in jQuery .serialize()
- Disable Browser onUnload on certain links?
- how to get selected text from iframe with javascri
You can use jQuery Validation and, in a single HTML line, you can validate the email and the email validation message:
type="email" required data-msg-email="Enter a valid email account!"
You can use the data-msg-email parameter to place a personalized message or otherwise do not place this parameter and the default message will be displayed: "Please enter a valid email address."
Full example:
Use jquery.validate.js,it have Microsoft ajax CDN.
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:See Email method documentation for details and samples.
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:
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:
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.
For thoose who want to use a better maintainable solution than disruptive lightyear-long RegEx matches, I wrote up a few lines of code. Thoose who want to save bytes, stick to the RegEx variant :)
This restricts:
Anyways, it's still possible to leak through, so be sure you combine this with a server-side validation + email-link verification.
Here's the JSFiddle