Skip to content

Instantly share code, notes, and snippets.

@oliveagle
Created April 25, 2013 15:13
Show Gist options
  • Save oliveagle/5460474 to your computer and use it in GitHub Desktop.
Save oliveagle/5460474 to your computer and use it in GitHub Desktop.
javascript: validate chinese mobile number
function isMobile(object) {
var s = document.getElementById(object.id).value;
var reg0 = /^13\d{5,9}$/;
var reg1 = /^153\d{4,8}$/;
var reg2 = /^159\d{4,8}$/;
var reg3 = /^0\d{10,11}$/;
var my = false;
if (reg0.test(s)) my = true;
if (reg1.test(s)) my = true;
if (reg2.test(s)) my = true;
if (reg3.test(s)) my = true;
if (s !== "") {
if (!my) {
// alert('请输入正确的手机号码');
object.value = "";
object.focus();
return false;
}
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment