ASP.net数值验证 [英] ASP.net numeric validation
本文介绍了ASP.net数值验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请任何人为我提供用于数字验证的C#代码.
please any one provide me the c# code for numeric validation.
推荐答案
Try:
Try:
int i;
if (!Int.TryParse(myStringToValidate, out i))
{
// Failed validation
}
如果您指的是数字验证,请查看以下博客文章:中的数字验证使用正则表达式的文本框
来自博客文章:
只有数字可以输入该文本框
我们可以为此使用正则表达式验证器:
将以下值分配给验证表达式属性:^ \ d +
Hi,
If it''s number validation that your referring to, when have a look at the following blog post: Numeric validation in Textbox using regular expressions
From the blog post:
Only numbers can enter into that Textbox
We can use Regular expression validator for this:
Assign the following value to the validation expression property: ^\d+
<br />
<pre><br />
<asp:TextBox ID="TextBox1" runat="server" Style="z-index: 100; left: 259px; position: absolute;<br />
top: 283px" ValidationGroup="check"><br />
<br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"<br />
ErrorMessage="Please Enter Only Numbers" Style="z-index: 101; left: 424px; position: absolute;<br />
top: 285px" ValidationExpression="^\d+
这篇关于ASP.net数值验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文