Regular Expression to accept specific Alphabets (ABCD) in TextBox in ASP.Net

Last Reply one month ago By dharmendr

Posted one month ago

Hello,

How can i validate textbox control only for four letters, A,B,C,D

No one can enter any text without these letters.

thank you

You are viewing reply posted by: dharmendr one month ago.
Posted one month ago

Hi Hariom,

Use RegularExpression Validator.

Check this example. Now please take its reference and correct your code.

HTML

<asp:TextBox ID="TextBox1" runat="server" /><br />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBox1"
    ForeColor="Red" ValidationExpression="[ABCD]*$" ErrorMessage="*Valid characters: A,B,C,D." /><br />
<asp:Button ID="Button1" Text="Validate" runat="server" />

Screenshot