I have a ASP.NET regular expression validator and how do I express:
“If the value to be tested is empty or contains [a-zA-Z0-9\s]+ elements?”
in regex?
I have to test a TextBox in ASP.NET, and while submitting the request, I would want the regular expression validator attached to TextBox to allow submitting the form if it contains characters, numbers or is empty.
matched example 1. "This is a good 1"
matched example 2. ""(empty)
unmatched example 1. "what is this ****?" (because it contains ‘*’ and ‘?’)
Since no one has actually posted it as an answer yet…
Just change the
+to a*in your regex. The former means match 1 or more, whereas the latter matches 0 or more. This is what you want since you want to allow blanks.