1. 程式人生 > >【2018-12-10】漢字、手機號碼驗證

【2018-12-10】漢字、手機號碼驗證

1、手機號碼驗證

checkPhoneNum(num) {   var phonetel = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;   var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;   if (num.length != 11 && mobile.length > 0) {     //手機號錯誤,長度有誤     return false;   }   if (!myreg.test(num)) {    //手機號有誤    return false;   }   return true;  //如果以上情況都沒發生則為正確手機號 },

2、判斷是否為漢字

isCharacter(word){   let re = new RegExp("^[\u4e00-\u9fa5]");   return re.test(word)  //如果為漢字則返回true }