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

Last Reply 4 months ago By dharmendr

Posted 4 months ago


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 4 months ago.
Posted 4 months ago

Hi Hariom,

Use RegularExpression Validator.

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


<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" />