var LayVerifyExtend = { notnullNonnegativeInteger: function (value, item) { //value:表單的值、item:表單的DOM對象 if (!/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\d+)?$/.t ...
var LayVerifyExtend = {
notnullNonnegativeInteger: function (value, item) { //value:表單的值、item:表單的DOM對象
if (!/^-?(?:\d+|\d{1,3}(?:,\d{3})+)(?:\d+)?$/.test(value))
return '只能輸入非負整數!';
},
maxlength: function (value, item) { //value:表單的值、item:表單的DOM對象
if (GetLength(value) > item.maxLength)
return '只能輸入' + item.maxLength + '個字元!';
},
PHONE: function (value, item) { //value:表單的值、item:表單的DOM對象 (驗證手機號非必填)
if (value.length > 0 && value != "" && !(/^1[3456789]\d{9}$/.test(value)))
return '手機號格式錯誤!';
},
IdCard: function (value, item) {//驗證身份證號是否正確
//var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;
//if (reg.test(value) === false) {
// return '身份證格式錯誤!';
//}
var val = value;
if (val == '') {
//身份證號不能為空
//return '身份證號不能為空!';
}
else {
if (val.length==18 && val.substr(val.length - 1, val.length) == "x") {
val = val.substring(0, 17) + "X";
$(item).val(val.substring(0, 17) + "X");
}
if (!CheckIdCard(val)) {
return '身份證格式錯誤!';
}
}
},
faxandphone: function (value, item) {//固話與手機驗證,非必填
var reg = /^((0\d{2,3}-\d{7,8})|(1[357894]\d{9}))$/;
if (value.length > 0 && reg.test(value) === false) {
return '電話格式錯誤!';
}
},
PositiveInteger: function (value, item) { //非空的正整數
debugger;
var reg = /^[+]{0,1}(\d+)$/
if (value.length > 0 && reg.test(value) === false)
return '只能輸入正整數!';
},
morezero: function (value, item) {//大於等於0
if (!/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/.test(value))
return '只能輸入大於等於0的數!';
},
nullormorezero: function (value, item) {//大於等於0
if (value != '') {
if (!/^[+]{0,1}(\d+)$|^[+]{0,1}(\d+\.\d+)$/.test(value))
return '只能輸入大於等於0的數!';
}
}
}
//載入公共驗證方法庫
form.verify(LayVerifyExtend);