layui: Enter the phone number or mobile phone number for verification (verify at the same time, enter one of them to pass the verification)

Recently, I received a request that no matter whether the mobile phone number or the phone number is entered, it must be verified, and the verification can be passed by entering one of them.

The code is shown in the figure below:

form.verify({
    
    
    phoneVal: function (value, item) {
    
    
         /*/^((\d{2,})-)(\d{2,30})(-(\d{2,}))?$/ 电话号码是不限制以0开头,最少输入2位后不限制位数,-之后最少输入2位,最大不超过30位,-最少输入2位后,不限制位数*/
         var  mobile = /^1[3|4|5|6|7|8|9]\d{
    
    9}$/ , phone = /^((\d{
    
    2,})-)(\d{
    
    2,30})(-(\d{
    
    2,}))?$/ ;
         var flag = mobile.test(value) || phone.test(value);
         if(!flag){
    
    
             return '请输入正确座机号码或手机号';
         }
     },
 });

Guess you like

Origin blog.csdn.net/li22356/article/details/124863676