I need regular expression to not allow only whitespaces in a field(the user should not enter just whitespaces in the field) but it can allow completely empty field and it can also allow string with whitespaces in between.
For example if I enter strings such as "This is a test" or "testing", the regular expression should pass validation. Also, If I don't enter anything in the field, it should pass validation. It should fail if I enter only whitespaces.
I tried the below mentioned ones but they fail.
1) ^[^-\s][a-zA-Z0-9_\s-]+$ - doesn't allow me to enter string with whitespaces in between
2) ^[^-\s][\w\s-]+$ - doesn't allow me to enter a string