简体   繁体   中英

regular expression for Alpha numeric,no spaces and 9 character input?

I have used

"^[a-zA-Z0-9]*$" 

for alphanumeric no spaces its working

now i have to limit only 9 character are allowed not more not less only 9

You can use curly braces to set limits on repetition:

"^[a-zA-Z0-9]{9}$" 

That will only match strings in which the pattern in the character class is repeated exactly 9 times.

Note that you can also use this to limit repetition to a range. This example would only match strings in which the character class pattern is repeated between 3 and 5 times:

"^[a-zA-Z0-9]{3,5}$"

And you can leave out the second number but keep the comma to specify a minimum number of repetitions, so this one will match "at least 5":

"^[a-zA-Z0-9]{5,}$"

The simplest way is to use Range Validator with your regular expression validator. or go with James Allardice solution, it may also help you. but I will suggest to use Range Validator as well with your Regular Expression click

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