简体   繁体   中英

Regular expression to match 9 characters where first 2 are letters and then 6 numbers and then 1 letter

I have an asp textbox control, now using regular expression I want to validate that control, which should contain 9 characters where first 2 are letters and then 6 numbers and then 1 letter. Any help would be appreciated.

If I know my Regex, you could use this: ^[a-zA-Z]{2}[\\d]{6}[a-zA-Z]{1}$ .

(The {1} at the end isn't needed, but I though it looks good...)

How you check that is up to you. You can do this in code-behind (since you're using asp.net) or JS.

EDIT: Should also work with a ValidationExpression .

Here's a sample of this in use:

<asp:TextBox ID="TB1" runat="server" />
<asp:RegularExpressionValidator ID="validator" runat="server" ControlToValidate="TB1" ErrorMessage="2 letters, 6 digits and a letter, hotshot!" ValidationExpression="^[a-zA-Z]{2}[\d]{6}[a-zA-Z]{1}$" />

验证器在行动

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