頁面字段比較多 ,自己寫了一個簡單的頁面驗證
var myinput2=new Array("enter_name:企業/個體工商戶名稱:C:*",
"enter_operator:經營者/法人:C:*",
"enter_uscc:注冊号/統一社會信用代碼:C:*",
"enter_register_time:企業/門店注冊時間:C:*",
// "enter_address:企業/門店位址:C",
"enter_area:企業/門店面積(平米):M:*",
"enter_brand:經營品牌:C:*",
"enter_period:經營年限:N:5",
"enter_tm_amount:近三月銷售總額(元):M:*",
"enter_tm_aveamount:近三月月均銷售額(元):M:*",
"enter_ly_amount:上年度銷售總額(元):M:*",
"enter_ly_profit:上年度利潤(元):M:*",
"enter_stock_value:庫存總價值(元):M:*",
"enter_gp_value:門店黃鉑金總價值(元):M:*",
"optEmploye:員勞工數:N:*"
)
function isgotoc(e){
for (x in e)
{
var str=e[x].split(":");
var number=$.trim($("#"+str[]).val());
if( number==""||number==null||(typeof number == undefined)){
layer.alert(str[]+"不能為空!");
return false;
}
if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]=='N'){
var reg = /^[1-9]\d*$/;
if(!reg.test(number) ){
layer.alert(str[]+"格式不正确!");
return false;
}
}
if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]=='M'){
var reg = /(?!0\.00)(\d+\.\d{0,2}$)/;
var reg1 = /^[1-9]\d*$/;
if(!(reg.test(number)||reg1.test(number)) ){
layer.alert(str[]+"格式不正确!");
return false;
}
}
if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]=='P'){
var reg = new RegExp("^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0,5-9]))\\d{8}$");
if (!reg.test(number)) {
layer.alert(str[]+"格式不正确!");
return false;
}
}
if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]=='T'){
var reg = new RegExp("^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$");
if (!reg.test(number)) {
layer.alert(str[]+"格式不正确!");
return false;
}
}
if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]=='TP'){
var reg1 = new RegExp("^((13[0-9])|(14[0-9])|(15([0-9]))|(18[0-9])|(17[0-9]))\\d{8}$");
var reg2 = new RegExp("^(0\\d{2}-\\d{8}(-\\d{1,4})?)|(0\\d{3}-\\d{7,8}(-\\d{1,4})?)$");
if (!(reg1.test(number)||reg2.test(number))) {
layer.alert(str[]+"格式不正确!");
return false;
}
}
if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]=='ID'){
var reg=/^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
if (!reg.test(number)) {
layer.alert(str[]+"格式不正确!");
return false;
}
}
if( str[]!=""&&str[]!=null&&(typeof str[] != undefined)&&str[]!='*'){
if(number.length>str[]){
layer.alert(str[]+"字元長度不能超過"+ str[]);
return false;
}
}
}
return true;
}