![](/img/trans.png)
[英]Phone Number Jquery validation … need numbers AND a few other characters
[英]Validation allow numbers only and phone number format on keypress using JQuery?
例:
见下图我到底需要什么
谢谢任何人帮助这个简单的代码...
我已经在屏蔽输入插件下面实现了您需要的功能。
步骤1:下载此插件
http://digitalbush.com/projects/masked-input-plugin
第2步:在CSHTML或HTml页面中编写以下代码。
<script type="text/javascript">
$(document).ready(function () {
$("#ContactNo").mask("(+9) 999-999-9999");
$("#txtContactNo2").mask("(+9) 999-999-9999");
});
</script>
希望这有效! 干杯:)
link this script to your page and do masking format as you want
<script src="../JavaScript/jquerymaskedinput.js" type="text/javascript"></script>
enter code here
and then write this inside script
$(function () {
Masktext();
});
function Masktext() {
$('#<%=txtTelephone.ClientID %>').mask('(999)999-9999');
$('#<%=txtFaxNumber.ClientID %>').mask('(999)999-9999');
$('#<%=txtTelephoneMD.ClientID %>').mask('(999)999-9999');
$('#<%=txtTelephoneHC.ClientID %>').mask('(999)999-9999');
}
您可以将事件侦听器添加到“提交”按钮(假设它具有一个类似buttonId
的ID),并检查数字是否有效(假设您的数字输入具有一个像numberId
的ID),如下所示:
var button = document.getElementById("buttonId"),
number = document.getElementById("numberId");
button.addEventListener("click", function(e) {
if (/[^0-9\-\+]/.test(number.value)) {
e.preventDefault();
alert("Please enter a valid telephone number!");
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.