正则表达式不适用于仅接受数字的文本框。 [英] Regular Expression Not working for text box accepting only number.
本文介绍了正则表达式不适用于仅接受数字的文本框。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在文本框中使用正则表达式只接受数字,但是当我输入字符时它显示消息仅输入否但当我点击更新时,字符会保存在数据库中。
我使用以下代码
< ; asp:RegularExpressionValidator ID = RegularExpressionValidator2 runat = server
ValidationExpression = (^ [ - ]?[1-9] \d + $ )|(^ [ - ] [1-9] $)|(^ 0 $)|(^ [ - ] [1-9] \d + \.\d $)|?(^ [ - ] ?[0-9] \.\d $) ControlToValidate =跨度> txtcontactno
< span class =code-attribute> ErrorMessage = 仅输入数字! ForeColor = 白色
ValidationGroup = 检查 字体大小 = 小 显示 = 动态 > < / asp:RegularExpressionValidator >
解决方案
)|(^ [ - ]?[1-9]
)|(^ 0
)|?(^ [ - ] [1-9] \d + \.\d
I m using Regular expression in text box to accept only number but when i enter characters It is displaying the message "Enter only no " but when I click on update the character get saved in database.
I m using the following code
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server"
ValidationExpression="(^[-]?[1-9]\d+$)|(^[-]?[1-9]$)|(^0$)|(^[-]?[1-9]\d+\.\d$)|(^[-]?[0-9]\.\d$)" ControlToValidate="txtcontactno"
ErrorMessage="Enter Number Only!" ForeColor="White"
ValidationGroup="check" Font-Size="Small" Display="Dynamic"></asp:RegularExpressionValidator>
解决方案
)|(^[-]?[1-9]
)|(^0
)|(^[-]?[1-9]\d+\.\d
这篇关于正则表达式不适用于仅接受数字的文本框。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文