The previous article introduced JS's regular verification method, this one is using jquery to run some of the methods of the example
JS section
<script>
$ (function () {
var Ok1=false;
var Ok2=false;
var Ok3=false;
var Ok4=false;
Verify User Name
$ (' input[name= ' username "]). focus (function () {
$ (this). Next (). Text (' User name should be between 3-20 bits '). Removeclass (' state1 '). addclass (' State2 ');
}). blur (function () {
if ($ (this). Val (). length >= 3 && $ (this). Val (). Length <=12 && $ (this). val () = ") {
$ (this). Next (). Text (' input succeeded '). Removeclass (' state1 '). addclass (' state4 ');
Ok1=true;
}else{
$ (this). Next (). Text (' User name should be between 3-20 bits '). Removeclass (' state1 '). addclass (' State3 ');
}
});
Verify Password
$ (' input[name= ' password "]). focus (function () {
$ (this). Next (). Text (' Password should be between 6-20 bits '). Removeclass (' state1 '). addclass (' State2 ');
}). blur (function () {
if ($ (this). Val (). length >= 6 && $ (this). Val (). Length <=20 && $ (this). val () = ") {
$ (this). Next (). Text (' input succeeded '). Removeclass (' state1 '). addclass (' state4 ');
Ok2=true;
}else{
$ (this). Next (). Text (' Password should be between 6-20 bits '). Removeclass (' state1 '). addclass (' State3 ');
}
});
Verification Confirmation Password
$ (' input[name= ' Repass "]). focus (function () {
$ (this). Next (). Text (' Enter the confirmation password to be the same as the above password, the same rules will be the same '). Removeclass (' state1 '). addclass (' State2 ');
}). blur (function () {
if ($ (this). Val (). length >= 6 && $ (this). Val (). Length <=20 && $ (this). val ()! = "&& $ (this) . val () = = $ (' input[name= "password"]). Val ()) {
$ (this). Next (). Text (' input succeeded '). Removeclass (' state1 '). addclass (' state4 ');
Ok3=true;
}else{
$ (this). Next (). Text (' Enter the confirmation password to be the same as the above password, the same rules will be the same '). Removeclass (' state1 '). addclass (' State3 ');
}
});
Verify Mailbox
$ (' input[name= ' email "]). focus (function () {
$ (this). Next (). Text (' Please enter the correct email format '). Removeclass (' state1 '). addclass (' State2 ');
}). blur (function () {
if ($ (this). Val (). Search (/\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) */) ==-1) {
$ (this). Next (). Text (' Please enter the correct email format '). Removeclass (' state1 '). addclass (' State3 ');
}else{
$ (this). Next (). Text (' input succeeded '). Removeclass (' state1 '). addclass (' state4 ');
Ok4=true;
}
});
Submit button, all validation passed by party can submit
$ ('. Submit '). Click (function () {
if (Ok1 && ok2 && ok3 && ok4) {
$ (' form '). Submit ();
}else{
return false;
}
});
});
</script>
<form action= ' do.php ' method= ' post ' >
User name: <input type= "text" name= "username" >
<span class= ' state1 ' > Please enter your username </span><br/><br/>
Password: <input type= "password" name= "password" >
<span class= ' state1 ' > Please enter your password </span><br/><br/>
Confirm Password: <input type= "password" name= "Repass" >
<span class= ' state1 ' > Please enter your confirmation password </span><br/><br/>
Email: <input type= "text" name= "email" >
<span class= ' state1 ' > Please enter your email address </span><br/><br/>
<a href= "javascript:;" ></a>
</form>
A validation instance method of jquery