I'm trying to write a regular expression that will validate that user input is greater than X number of non-whitespace characters. I'm basically trying to filter out begining and ending whitespace while still ensuring that the input is greater than X characters; the characters can be anything, just not whitespace (space, tab, return, newline). This the regex I've been using, but it doesn't work:
\s.{10}.*\s
I'm using C# 4.0 (Asp.net Regular Expression Validator) btw if that matters.
It may be easier to not use regex at all:
input.Where(c => !char.IsWhiteSpace(c)).Count() > 10
If whitespace shouldn't count in the middle, then this will work:
(\s*(\S)\s*){10,}
If you don't care about whitespace in between non-whitespace characters, the other answers have that scenario covered.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With