[英]How to add a hyphen in a TextBox input in ASP.NET?
I have an ASP.NET textbox where I want to add a hyphen in the textbox input if the length of the input is > 5. For example, if I type 123456789, the entry should show like this: 12345-6789 我有一个ASP.NET文本框,如果输入的长度> 5,我想在文本框输入中添加连字符。例如,如果键入123456789,则该条目应显示为:12345-6789
How to do this? 这个怎么做?
<asp:Button ID="Button1" runat="server" Text="Button" />
$('.phone').on('input', function() { this.value.length < 5 || this.value.charAt(5) == '-' || $(this).val( [this.value.slice(0,5), '-', this.value.slice(5)].join('') ); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <input type="text" name="phone" class="phone"/>
var value = $("#your-textbox-id-here").val();
if (value.length >= 5) {
value = value.substring(0, 5) + "-" + value.substring(5);
//console.log(value);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.