using Asp.Net RangeValidator for Int64

让人想犯罪 __ 提交于 2019-12-25 14:51:27

问题


Is there a way to use RangeValidator for large numbers (Int64 range)?


回答1:


After looking that this there is no clean way to do this with just a rangevalidator. I've listed the alternatives below that use the webforms validators.

HTML:

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  <asp:RangeValidator ID="RangeValidator1" ControlToValidate="TextBox1"
runat="server" ErrorMessage="Help" SetFocusOnError="True" Type="Double"></asp:RangeValidator>

HTML Alt:

You could use a combo here. One to verify that its in the 64 bit range and one to validate its just an integer. Seems clunky, but it should work.

<asp:RangeValidator ID="RangeValidator1" ControlToValidate="TextBox1"
    runat="server" ErrorMessage="Help" SetFocusOnError="True" Type="Double"></asp:RangeValidator>
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
      ControlToValidate="TextBox1" ErrorMessage="RegularExpressionValidator" 
      ValidationExpression="[1-9]\d*"></asp:RegularExpressionValidator>

Code Behind:

protected void Page_Load(object sender, EventArgs e) {
      this.RangeValidator1.MaximumValue = Int64.MaxValue.ToString();
    }


来源:https://stackoverflow.com/questions/5537971/using-asp-net-rangevalidator-for-int64

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!