Skip to content

Instantly share code, notes, and snippets.

@jay16
Created January 19, 2014 12:34
Show Gist options
  • Save jay16/8504275 to your computer and use it in GitHub Desktop.
Save jay16/8504275 to your computer and use it in GitHub Desktop.
<!--
监视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