js 正则判断是否是手机号

做项目时,遇到手机号注册,需要判断用户输入是否为手机号,就写了段正则判断.

js 如下

1
2
3
4
5
6
7
8
function checkMobile(str) {
var re = /^1\d{10}$/
if (re.test(str)) {
return true;
} else {
return false;
}
}

Adhere to original technology sharing, your support will encourage me to continue to create!