JavaScript Object-oriented thought to do form form verification code is very concise OH

Source: Internet
Author: User

<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

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.