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.