在asp文本框中只允许正数? [英] allow only positive number in asp textbox ?
本文介绍了在asp文本框中只允许正数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
hi
请问我怎么才允许整数正数插入到asp.net文本框中?
请帮助:)
解决方案
正值大于零。所以,测试这个值的逻辑就像这个,
if (Convert.ToInt16(textBox1.Text)> 0 ){
< span class =code-comment> // positive
} else {
// 负值
}
这将执行任一方法,具体取决于textBox1的值(您也可以使用自己的变量和控件)。
尝试使用两个CompareValidator
[ ^ ]验证人:
< pre lang =asp.net> < asp:TextBox id = YourTextBox runat = server / >
< asp:CompareValidator runat = server
ControlToValidate = YourTextBox
运算符 = DataTypeCheck
输入 = 整数
ErrorMessage = 输入有效的整数
显示 = 动态
文本 = *
/ >
< asp:CompareValidator runat = server
ControlToValidate = YourTextBox
运算符 = GreaterThanEqual
< span class =code-attribute> ValueToCompare = 0
类型 = 整数
< span class =code-attribute> ErrorMessage = 整数不能小于零
显示 = 动态
文字 = *
/ >
hi
please how can i allow only integer positive to insert into asp.net textbox ?
please help :)
解决方案
A positive value is greater than zero. So, the logic to test this value would be like this one,
if(Convert.ToInt16(textBox1.Text) > 0) { // positive } else { // negative value }
This would execute either method depending on the value of the textBox1 (you can use your own variables and controls here too).
Try using twoCompareValidator
[^] validators:
<asp:TextBox id="YourTextBox" runat="server" /> <asp:CompareValidator runat="server" ControlToValidate="YourTextBox" Operator="DataTypeCheck" Type="Integer" ErrorMessage="Enter a valid integer" Display="Dynamic" Text="*" /> <asp:CompareValidator runat="server" ControlToValidate="YourTextBox" Operator="GreaterThanEqual" ValueToCompare="0" Type="Integer" ErrorMessage="The integer cannot be less than zero" Display="Dynamic" Text="*" />
这篇关于在asp文本框中只允许正数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文