Reputation: 87
I have a problem with a RegularExpressionValidator in asp. I want to use it to validate a field in my page. This field is used to enter an alphanumeric value (which can contains any caracters between 0-9, a-z and A-Z). This value can have a maximum of 16 alphanumeric caracters. But, it can contains a boundless number of white spaces, placed anywhere in the string.
If I could, I would use a function such as "replace" in order to remove white spaces and just count the alphanumeric caracters. But, in the case of a RegularExpressionValidator, I just can use a regex ...
Any suggestions :-) ?
Here some value that I want to match :
BG R 7K8 15 H8 14
7H96EH L QP0 4634 94
8HL9Q2LRRP18M634
Upvotes: 1
Views: 2332
Reputation: 2553
This should solve the case:
^([A-Za-z0-9]\s*){1,16}$
Explanation:
^ # Start of string
( # Start of group
[A-Za-z0-9] # Allow a-Z and 0-9
\s* # Followed by any number of spaces, including none
) # End of group
{1,16} # Repeat group 1-16 times
$ # End of string
Upvotes: 3