let reg=/^$|^[1-9]\d*$/;
if(!reg.test(course1)){
showToast.msg('套餐1只能输入非零正整数');
return false;
}
if(!reg.test(course2)){
showToast.msg('套餐2只能输入非零正整数');
return false;
}
The regular expression written as above will work, but the regular expression written as follows will be invalid. Entering letters can also pass the verification!
if((!reg.test(course1))&&(!reg.test(course2))){
showToast.msg('套餐只能输入非零正整数');
return false;
}
淡淡烟草味2017-07-05 10:53:10
course1='1', course2='a', this case will not enter your method.
It should be the relationship of ||.
The code is modified as follows:
if((!reg.test(course1))||(!reg.test(course2))){
showToast.msg('套餐只能输入非零正整数');
return false;
}