I have an issue where I need to use a RegularExpressionValidator
to limit the length of a string to 400 Characters.
My expression was .{0,400}
My question: Is there a way to limit the length of characters to 400 without taking into consideration blank spaces?
I want to be able to accept blank spaces in the string but not count it in the length. Is this possible?
I pretty much agree with Greg, but here's the regex you want:
^\s*([^\s]\s*){0,400}$
@Boopid: If you really meant only the space character, replace \s with a space in the regex.
It sounds like you might want to write your own validator class instead of using the RegularExpressionValidator. Regular expressions certainly have their uses, but this doesn't sound like one of them.
Your custom validator could remove all the spaces, then check the length of the string. Ultimately, the code will be more readable than a regular expression that does the same thing.
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