2

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

This is indeed working. One additional question here: I'm using an asterix (*) as wildcard. Is it possible to ommit that character also from the count?
@Koen Sure, to match either a whitespace or a start, replace \s with [\s*]: '([\s*]*\w[\s*]*){3}'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.