Created
January 19, 2014 12:34
-
-
Save jay16/8504275 to your computer and use it in GitHub Desktop.
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
<!-- | |
监视input输入为手机号 | |
即输入内容为11位数字 | |
--> | |
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> | |
<input type="text" id="number"> | |
<script> | |
function chk_phone_number(input) { | |
if(input.val().toString().match(/^[-]?[0-9]+[\.]?[0-9]*$/)==null || | |
input.val().toString().length != 11) { | |
input.css("color","red"); | |
} else { | |
input.css("color","blue"); | |
} | |
} | |
$(function(){ | |
chk_phone_number($("#number")); | |
$("#number").keyup(function(){ | |
chk_phone_number($(this)); | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment