Created
April 25, 2013 15:13
-
-
Save oliveagle/5460474 to your computer and use it in GitHub Desktop.
javascript: validate chinese mobile number
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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