正则验证手机号

    
       
        /**
        * 校验手机号
        * @param {string} phone 手机号
        * @return {boolean} 手机号正确返回true,反之则false
        */
        export function isPhone(phone) {
            const rule = /^1\d{10}$/;
        return rule.test(phone);
        }
        ----------------------------------------------------
        // 实例
        import {isPhone} from '../../../utils/validate.js'
        savaData() {
        if(isPhone(this.data.tel)==false){
          Notify('请输入正确的手机号');
          return    
        }else{
          request({
            url: '/api/Address/AddAddress',
            isLock: true,
            data: {
              name: this.data.name,
              tel: this.data.tel,
              provice: this.data.provice,
              city: this.data.city,
              county: this.data.county,
              detail_address: this.data.address,
              is_default: this.data.isDefault
            }
          }).then(res => {
            if (res.data.code == 200) {
              wx.showToast({
                title: '保存成功',
              })
              wx.navigateTo({
                url: '../../../personalCenter/pages/addressManagement/addressManagement',
              })
            } else {
              Notify(res.data.msg);
            }
    
          })  
        }
    
         
    
发布时间:2019-10-06