I have an application in which I want to validate a text box that it will take decimal value. I would like to use a regular expression validator for this. What would this expression look like?
我有一个应用程序,我想验证一个文本框,它将取十进制值。我想为此使用正则表达式验证器。这个表达式会是什么样的?
5 个解决方案
#1
5
I wouldn't use a regular expression - create a custom validator that uses Decimal.TryParse
under the covers.
我不会使用正则表达式 - 创建一个使用Decimal.TryParse的自定义验证器。
Edit: To be fair to the question, here is a regular expression that would do the trick:
编辑:为了公平对待这个问题,这里有一个正则表达式可以解决问题:
^\d*\.?\d+$
#2
0
just the regex would be
只是正则表达式
`\d*`
#3
0
I'd use a CompareValidator - for type decimal And a Required field Validator - so blank is not allowed But regular expression is accepable this link gives some examples http://msdn.microsoft.com/en-us/library/ms998267.aspx
我使用CompareValidator - 对于十进制类型和一个必填字段验证器 - 所以不允许空白但正则表达式是可接受的这个链接提供了一些示例http://msdn.microsoft.com/en-us/library/ms998267.aspx
#4
0
I say to keep using the Regular Expression Validator, you'll get the added benefit of client-side validation with it.
我说要继续使用正则表达式验证器,您将获得客户端验证的额外好处。
Here is a list of regular expressions related to decimals: http://regexlib.com/DisplayPatterns.aspx?cattabindex=2&categoryId=3
以下是与小数相关的正则表达式列表:http://regexlib.com/DisplayPatterns.aspx?cattabindex = 2&categoryId = 3
#5
0
I would use a CompareValidator and use Regular Expression
我会使用CompareValidator并使用正则表达式
^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$
This allow all decimal number, exclude all alphanumeric caracter
这允许所有十进制数,排除所有字母数字字符
e.g.
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
runat="server"
ErrorMessage="Only Decimal Value"
ValidationExpression="^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$">
</asp:RegularExpressionValidator>
#1
5
I wouldn't use a regular expression - create a custom validator that uses Decimal.TryParse
under the covers.
我不会使用正则表达式 - 创建一个使用Decimal.TryParse的自定义验证器。
Edit: To be fair to the question, here is a regular expression that would do the trick:
编辑:为了公平对待这个问题,这里有一个正则表达式可以解决问题:
^\d*\.?\d+$
#2
0
just the regex would be
只是正则表达式
`\d*`
#3
0
I'd use a CompareValidator - for type decimal And a Required field Validator - so blank is not allowed But regular expression is accepable this link gives some examples http://msdn.microsoft.com/en-us/library/ms998267.aspx
我使用CompareValidator - 对于十进制类型和一个必填字段验证器 - 所以不允许空白但正则表达式是可接受的这个链接提供了一些示例http://msdn.microsoft.com/en-us/library/ms998267.aspx
#4
0
I say to keep using the Regular Expression Validator, you'll get the added benefit of client-side validation with it.
我说要继续使用正则表达式验证器,您将获得客户端验证的额外好处。
Here is a list of regular expressions related to decimals: http://regexlib.com/DisplayPatterns.aspx?cattabindex=2&categoryId=3
以下是与小数相关的正则表达式列表:http://regexlib.com/DisplayPatterns.aspx?cattabindex = 2&categoryId = 3
#5
0
I would use a CompareValidator and use Regular Expression
我会使用CompareValidator并使用正则表达式
^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$
This allow all decimal number, exclude all alphanumeric caracter
这允许所有十进制数,排除所有字母数字字符
e.g.
<asp:RegularExpressionValidator
ID="RegularExpressionValidator1"
runat="server"
ErrorMessage="Only Decimal Value"
ValidationExpression="^\d*[0-9](|.\d*[0-9]|,\d*[0-9])?$">
</asp:RegularExpressionValidator>