Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to not allow user to input numbers in textbox

I am trying to make a textbox that doesn't allow to input numbers

I have tried some codes but doesn't work

Here is what I have tried:

<asp:RegularExpressionValidator runat="server" ID="txtSurnameValidation" 
     ControlToValidate="txtSurname" ValidationExpression="[a-zA-Z ]*$" Display="Dynamic">
</asp:RegularExpressionValidator>
like image 415
charles david Avatar asked Dec 18 '25 00:12

charles david


1 Answers

its working but its not showing any message because you did not set any message in case validation fails so add ErrorMessage="* Alphabets Only" so that if someone enters numbers it will show this message

 <asp:TextBox runat="server" ID="txtSurname"></asp:TextBox>
        <asp:RegularExpressionValidator runat="server" ID="txtSurnameValidation" 
     ControlToValidate="txtSurname" ValidationExpression="[a-zA-Z ]*$" ErrorMessage="* Alphabets Only" Display="Dynamic">
</asp:RegularExpressionValidator>
like image 52
Usman Avatar answered Dec 20 '25 14:12

Usman