检查一个字符串是否符合手机号码格式
移动号码段:139、138、137、136、135、134、150、151、152、157、158、159、182、183、187、188、147 联通号码段:130、131、132、136、185、186、145、166、199 电信号码段:133、153、180、189
import { isPhoneNumber } from "check-string"; ... let str = "15811111111" let result = isPhoneNumber(str, { canNull: true }); //str可以为null if(!result.success) { console.log(result.error.code); // 输出错误编号 console.log(result.error.cn); // 输出错中文错误 console.log(result.error.en); // 输出错英文错误 }
被检查的字符串
检查一个字符串是否符合手机号码格式