Koen
Koen

Reputation: 2571

Textboxvalidation: Empty or minimum 3 characters (spaces do not count)

I have some textboxes I'm using as search-fields. The textbox can be empty, but when a search-criteria is filled in, it must be at least 3 characters long, ignoring the spaces in the count.

I've found that a regularexpressionvalidator validates true when the textbox is empty, so that part is ok.

Q: regex for a minimumlenth of 3 characters. Spaces are allowed, but should not count in the length.

Thanks.

Upvotes: 2

Views: 2634

Answers (1)

jcollado
jcollado

Reputation: 40394

Have you tried something like this?

'(\s*\w\s*){3}'

This regular expression looks for a character (\w) optionally surronded by any whitespace (\s*) three times ({3}), which is what you're looking for.

Note: I don't know asp.net, but I think the regular expression is all you need to solve the problem.

Upvotes: 2

Related Questions