admin管理员组

文章数量:1277270

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

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

Share Improve this question asked Apr 24, 2013 at 6:53 Rahul ChowdhuryRahul Chowdhury 1,1586 gold badges32 silver badges58 bronze badges 1
  • "^[a-zA-Z0-9]*$" allows empty string while "^[a-zA-Z0-9]+$" requires at least one character. – Rick Putnam Commented Jul 7, 2015 at 19:43
Add a ment  | 

2 Answers 2

Reset to default 12

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 ma 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

本文标签: javascriptregular expression for Alpha numericno spaces and 9 character inputStack Overflow