Rahul Chowdhury
Rahul Chowdhury

Reputation: 1158

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

Upvotes: 1

Views: 8014

Answers (2)

Rocky
Rocky

Reputation: 4524

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

Upvotes: 0

James Allardice
James Allardice

Reputation: 166021

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,}$"

Upvotes: 12

Related Questions