简体   繁体   中英

Customize regular expression to allow alphabets and dots in textbox

Hello friends In my application I want to customize regular expression in such a way that it will allow character and dot only. For eg. I could be be able to enter MCA or MCA any of these. For this task how to customize regular expression? I tried [a-zA-Z] followed by\\ and dot in side bracket but is not working. I also tried [ABCD] just for testing but it shows invalid text for ABC. What might be the reason???? Thanks to all...

You will need to escape the dot as in regex it normally means 'any character'

[a-zA-Z\.]+

in c# you will need to deinfe the regex string as follows:

var r = @"[a-zA-Z\.]+";

Edit based on comment:

<asp:TextBox ID="qualificationBox" runat="server" Width="250px"></asp:TextBox>
<asp:RegularExpressionValidator ID="NameRequiredValidator" runat="server" 
 ErrorMessage="Please Enter Name" ControlToValidate="qualificationBox" 
 ValidationExpression="[a-zA-Z\.]+"></asp:RegularExpressionValidator>

您可能需要加倍转义反斜杠:

[a-zA-Z\\.]+

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM