Jquery+ to implement unified form validation _jquery

Source: Internet
Author: User
Tags eval

Form verification has been very cumbersome, especially the larger form, if each input to write the verification of the individual is simply to write the dead, recently wrote a small paragraph of JS Unified verification of the content of the form is correct.

Using this code will no longer need to judge each input write format, just the correct format of the regular expression in the datatype can be, submit the form button only need to bind the Checkform function on it.

Do you have any suggestions to comment on?

<input type= "text" datatype= "regular"/>/

/form verification
//Click Next event
function Checkform (form) {
var success = true;
$("." +form+ "Input"). each (function () {
var $that = $ (this);
var dataType = eval ($that. attr ("DataType"));
if (datatype!=undefined) {
if ($that. val (). Match (DataType)) {
$that. Removeclass ("borderred");
else{
$that. focus ();
$that. addclass ("borderred");
Success = false;
return false;}}
)
return success;
}

Bind Blur Focus Event $ (document) to each label with the datatype attribute

. On ("Blur", "Input", function () {
var $that = $ (this);
var dataType = eval ($that. attr ("DataType"));
if (datatype!=undefined) {
if ($that. val (). Match (DataType)) {
$that. Removeclass ("borderred");
else{
$that. addclass ("borderred");
}
)
$ (document). On (' Focus ', ' input ', function () {
$ (this). Removeclass ("borderred");
});

The above content for everyone to share the jquery+ is to achieve a unified form verification, I hope you like.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.