I would just like to know if there is a way in ASP.NET to allow only numbers in textboxes with textmode="number"
when I use this:
<asp:TextBox runat="server" TextMode="Number" ID="TextBoxDuration" Width="250"></asp:TextBox>
<asp:RequiredFieldValidator ControlToValidate="TextBoxDuration" runat="server" ErrorMessage="Dieses Feld darf nicht leer sein" /><br />
<asp:RegularExpressionValidator runat="server" ControlToValidate="TextBoxDuration" validationexpression="((\d+)((\.\d{1})?))$" ErrorMessage="Nur Zahlen" />
users can still input the char e
and +, -
I don't like to use normal Textbox with the same Regularexpressionvalidator
(which actually would work)
example:
You can simply use regular expression validator as
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="RegularExpressionValidator1"
ControlToValidate="TextBox1" runat="server"
ErrorMessage="Only Numbers allowed"
ValidationExpression="\d+">
</asp:RegularExpressionValidator>
Also you can use the below regular expression to make the text-field as 12 digit number to be added.(madatory)
^[0-9]{12}$
Also you can make the field as between 10 and 12 digits (mandatory) as below
^[0-9]{10-12}$
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With