我在使用jQuery验证器验证电话号码时遇到了问题。因此,在一个包含电话号码输入框的表单中,我使用了jQuery的附加方法来验证电话号码。以下是代码:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>stuff/title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/jquery.validate.min.js"></script>
<script type="text/javascript" src="https://ajax.aspnetcdn.com/ajax/jquery.validate/1.9/additional-methods.min.js"></script>
</head>
<body>
<script>
$(document).ready(function(e) {
var val = $('#everything').validate({
onkeyup: false,
errorClass: "req_mess",
ignore: ":hidden",
rules: {
phone: {
required: true,
minlength: 10,
phoneUS: true
}
},
messages: {
phone: {
required: "Please enter your phone number",
phoneUS: "Please enter a valid phone number: (e.g. 19999999999 or 9999999999)"
}
}
});
});
</script>
<form name="everything" id="everything" action="Private/Insert.php" method="post" style="display:none;" >
Phone Number: <input type="text" name="phone" id="phone"/>
</form>
</body>
</html>
电话号码列的数据库看起来像这样:
有时它会正确地插入完整的电话号码(用红色划掉),但有时它只插入3个数字。我不知道为什么。这可能与Internet Explorer有关吗?有人遇到过这个问题吗?有人知道为什么会发生这种情况吗?如果需要,以下是整个jquery验证代码。