<meta charset=utf-8/>
<!--introduction of jquery-->
<!--coder:[email protected] Sun Yarong--->
<script src= "Jquery-1.7.2.min.js" ></script>
<script>
var obj = {
Res:true,
Nick_fun:function (O,tip) {
if (this.res==true) {
O.siblings ("span"). CSS ("Color", "blue");
}else{
O.siblings ("span"). CSS ("Color", "red");
}
O.siblings ("span"). HTML (TIP);
}
}
$ (function () {
var regex = new RegExp ("^ ([\u4e00-\ufa29]) {1,10}$");
var regmob =/(1[3458]\d{9},) *1[3458]\d{9}/g;
var regem =/^ ([a-za-z0-9_\.\-]) +\@ (([a-za-z0-9\-]) +\.) + ([a-za-z0-9]{2,4}) +$/;
$ (". Name"). blur (function () {
var v = $ (this). Val ();
var re = regex.test (v);
Obj.res = re;
Re==true? Obj.nick_fun ($ (this), "name entered correctly!" "): Obj.nick_fun ($ (this)," Name is Kanji! ");
})
$ (". Email"). blur (function () {
var v = $ (this). Val ();
var re = regem.test (v);
Obj.res = re;
Re==true? Obj.nick_fun ($ (this), "Mailbox input is correct! "): Obj.nick_fun ($ (this)," the mailbox input format is incorrect! ");
})
$ (". Mobile"). blur (function () {
var v = $ (this). Val ();
var re = regmob.test (v);
Obj.res = re;
Re==true? Obj.nick_fun ($ (this), "phone number entered correctly!" "): Obj.nick_fun ($ (this)," wrong phone number entered! " ");
})
})
</script>
<body>
<form>
<div> Name: <input type= ' text ' name= "name" class= "name"/><span></span></div>
<div> Email: <input type= ' text ' name= "email" class= "email"/><span></span></div>
<div> phone Number: <input type= ' text ' name= "mobile" class= "mobile"/><span></span></div>
<input type= "button" value= "click" id= "CK"/>
</form>
</body>
JavaScript Object-oriented thought to do form form verification code is very concise OH