Form verification, mobile phone, QQ, e-mail, digital, ZIP code, ID, cell phone number & phone

Source: Internet
Author: User

Well, write a verification of your own form, temporary.

Also updated later: now dependent on JQ

    //Form Validation    functionTestinput (o,attr,yfn,nfn,run) {varRe = {            ' Age ':/^[^0]\d{0,2}$/,            ' Null ':/\s/,            ' QQ ':/^[1-9][0-9]{4,9}$/,//QQ' Email ':/^\[email protected][a-z0-9]+ (\.[ a-z]+) {1,3}$/,//e-Mail' Number ':/^\d+$/,//Digital' Mail ':/^[1-9]\d{5}$/,//Postal Code' ID ':/^[1-9]\d{14}| [1-9]\d{17}| [1-9]\d{16}x$/,//ID Card' Call ':/(^ (\d{3,4}-)? \d{7,8}) $| (1[3,4,5,8][0-9]{9})///Mobile phone number & phone        }; functionGo () {functionFyes () {O.removeclass (' No_verify '); if(YFN) yfn ()returnO.value; }            functionfno () {O.addclass (' No_verify '); if(NFN) NFN () Console.log (' Error message: ' +attr)return false; }            if(attr &&typeofattr! = ' number '){                if(O.val () &&re[attr].test (O.val ())) {Fyes ()}Else{FNO ()}}Else if(attr &&typeofattr = = ' Number '){                if(O.val () .length>attr) {Fyes ()}Else{FNO ()}}Else{                if(O.val ()) {Fyes ()}Else{FNO ()}}}; if(run) {Go ()}//run=true Verify the formO.blur (GO); };

Trial method://testinput (JQ object, ' validation Attribute | | | No value validation form is not empty | | The number verifies that the byte is not less than this number ', ' Verify succeeded Fn ', ' failed FN ', do not self-execute)

(Verify successful return value, unsuccessful return false This also adds a class style to the form: no_verify)

var f2=testinput ($ (' #phone '), ' call ', ' ', ', false)//verify that the phone or phone is not

var f5=testinput ($ (' #userName '), ', ', ', ', false)//form not empty

var f12=testinput ($ (' #reason '), +, ",", false) //form not less than 20

Form verification, mobile phone, QQ, e-mail, digital, ZIP code, ID, cell phone number & phone

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.