【发布时间】:2019-01-20 19:31:07
【问题描述】:
我需要验证我的input type="text",当按键时最小值为 7,最大值为 13。我还需要验证是否只输入数字。我尝试了一些参考堆栈,但未能解决。任何人都可以帮助我实现这一目标。
$("#phone").bind("keyup keydown", function() {
var amount = parseFloat($(this).val());
if (amount) {
if (amount > 7 || amount < 13) {
$("span.phonealert").html("Your number must be between 7 and 13");
} else
if(amount < 13) {
$("span.phonealert").html("valid phone number");
}
} else {
$("span.phonealert").html("Enter numbers only");
}
});
#phone {
height:40px;
width:200px;
padding:5px;
font-size:15px;
}
<html>
<head>
<script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<form>
<input type="text" name="phone" id="phone" maxlength="13" autocomplete="off" placeholder="eg: 01234567890" value=""/>
<span class="phonealert"></span>
</form>
</body>
</html>
【问题讨论】:
-
您是否要验证电话号码,最少 7 位,最多 13 位。
-
@iNullPointer 是的。
-
检查我的答案。
-
@iNullPointer 可以根据我的问题发送示例链接并带有警报消息。
标签: javascript jquery html css validation