本文介绍了如何在文本框中只允许4位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 大家好 我在触摸屏环境中工作,我有一个屏幕,我有数字按钮0-9,我正在输入密码4位数。 我更改了该文本框的MaxLength属性。 当我使用键盘输入该文本框的值时,它工作正常意味着它不允许我输入超过4位数,但当我使用数字按钮进入时,它允许我输入更多然后4. 请告诉我是什么问题。 谢谢解决方案 您可以尝试使用 MaskedTextBox Class [ ^ ] 可能更容易控制输入。 < asp:TextBox ID = txtdigit runat = server MaxLength = 4 > < / asp:TextBox > < asp:RegularExpressionValidator ID = RegularExpressionValidator1 ControlToValidate = txtdigit ValidationExpression = ^ [0-9] + runat = server ErrorMessage = 请仅输入数值。 > < / asp:RegularExpressionValidator > Hi allI am working in a touch screen environment where I am having one screen where i have number buttons 0-9 using which i am entering PIN number of 4 digit.I changed the MaxLength property of that text box.when i m entering the value to that text box using keyboard, it's working fine means it is not allowing me to enter more then 4 digits,but when i m entering using the number buttons, it is allowing me to enter more then 4.Please tell me what is the problem.Thank you 解决方案 You could try to use the MaskedTextBox Class[^]It might make it easier to control the input.<asp:TextBox ID="txtdigit" runat="server" MaxLength="4"></asp:TextBox> <asp:RegularExpressionValidator ID="RegularExpressionValidator1" ControlToValidate="txtdigit" ValidationExpression="^[0-9]+" runat="server" ErrorMessage="Please enter only numeric value."></asp:RegularExpressionValidator> 这篇关于如何在文本框中只允许4位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 00:56
查看更多