JS Data Check Plugin

Source: Internet
Author: User
Tags string to json

//Data Validation/** *{type: "type", notempty:true,regxp:reg,maxlength:number,minlength number,message: ' Error message '} * Check type Type:phone (phone number )/mail (mailbox)/mount (integer)/money (amount)/passwd (password)/reg (regular authentication)/notnull (cannot be empty) required * can be empty emptable:true (true can be NULL, false cannot be empty) The default is False) * Regular match regexp (content with this regular validation, type needs to be Reg, otherwise invalid message error message) type is reg required * Failure prompt content message:string type is Reg/notnul L Time Required * Example: {type:phone,notempty:true} * @constructor*/varTestData =function () {    varme = This; //All calibration MethodsMe. Testall =function(){        varInputlist = $ ("[Validata]"); vardata = '; varresult =true;  for(vari=0;i<inputlist.length;i++) {Data= Inputlist[i].getattribute ("Validata"); if(data) {data=Me.strtojson (data); if(!me.ifnull (Data.type)) {                    varValue =Inputlist[i].value; if(!me. Testbytype (Data,value)) {return false; }                }Else{Console.log ("Type cannot be empty")                }            }        }        returnresult;    }; //verify based on typeMe. Testbytype =function(data,value) {if(Data.type = = ' phone '){            if(value) {returnMe.isphone (value); }Else{                returnMe.isempty (", data. EmpTable, ' mobile phone can't be empty ')            }        }Else if(Data.type = = ' mail '){            if(value) {returnMe.ismail (value); }Else{                returnMe.isempty (", data. EmpTable, ' mailbox cannot be empty ')            }        }Else if(Data.type = = ' passwd '){            if(value) {returnme.ispwd (value); }Else{                returnMe.isempty (", data. EmpTable, ' Password cannot be empty ')            }        }Else if(Data.type = = ' Reg '){            if(Me.ifnull (Data.regex)) {Console.log (' parameter missing regular expression ')                return false; }Else if(Me.ifnull (data.message)) {Console.log (' parameter message as cue message ')                return false; }            returnMe.regtset (value,data.regex,data.message)}Else if(Data.type = = ' Mount '){            if(value) {returnMe.isnumber (value); }Else{                returnMe.isempty (", data. EmpTable, ' Quantity cannot be empty ')            }        }Else if(Data.type = = ' Money '){            if(value) {returnMe.ismoney (value); }Else{                returnMe.isempty (", data. EmpTable, ' The amount cannot be empty ')            }        }Else if(Data.type = = ' Notnull '){            returnMe.isempty (Value,data. emptable,data.message)}}//Regular ValidationMe.regtset =function(o,regex,message) {varReg =regex; if(o) {if(!reg.test (o)) {wrap.alert (message);//validation does not pass the hint                return false; }        }Else{            returnMe.isempty ("',false, message); }        return true; }    //password CheckMe.ispwd =function(o) {returnMe.regtset (o,/^[0-9a-za-z]+$/, ' Password format error '); }    //Mobile phone number checkMe.isphone =function(o) {//var phone_reg =/^ ((13[0-9]{1}) | ( 15[0-9]{1}) | (18[0-9]{1})) +\D{8}) $/;        varPhone_reg =/^ (1+\d{10}) $/; returnMe.regtset (O,phone_reg, ' Please enter a valid mobile phone number ')); }    //Mailbox CheckMe.ismail =function(o) {varMail_reg =/^ ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9][email protected] ([a-za-z0-9]+[_|\_|\.]?) *[a-za-z0-9]+\. [A-za-z] {2,3}$/; returnMe.regtset (O,mail_reg, ' Please enter a valid mailbox ')); }    //Amount CheckMe.ismoney =function(o) {varMoney_reg =/^ ([1-9][\d]{0,7}|0) (\.[ \d]{1,2})? $/; returnMe.regtset (O,money_reg, ' Please enter a valid amount ')); }    //Quantity CheckMe.isnumber =function(o) {varNumber_reg =/^[1-9]\d*$/; returnMe.regtset (O,number_reg, ' Please enter the correct quantity '); }    //Allow NULL to allow NULL to return true does not allow null and is NULL, return false print error messageMe.isempty =function(o,emptable,message) {if(emptable) {return true; }Else{            if(o = = Undefined | | o = = "" | | o = =NULL) {wrap.alert (message); return false; }            return true; }    }    //is nullMe.ifnull =function(o) {returno = = Undefined | | o = = "" | | o = =NULL    }    //string to JSONMe.strtojson =function(str) {varJSON = eval (' (' + str + ') '); returnJSON; }}

JS Data Check Plugin

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.