I would like to ask if there is a RegEx to prevent or avoid entering only a space or many space and inserting it to the database. I am using ASP.NET and MVC, in my forms.
The conditions are as follows:
- "[space][space]" = should not be accepted or inserted in the database
- "[space]" = should not be accepted or inserted in the database
- "[space]name = should be accepted or inserted in the database
- "name[space]of[space]a[space]person" = should be accepted or inserted in the database
What I am trying to prove is that, if I am testing, a space should not be accepted, but If I type a name example "Mary Jane" it will be accepted or even a letter. I even tried s or S but still would not work.
Hoping you could help me with this.
2
Answers
Use the String.Trim method here this will get rid of all leading and trailing spaces.
You can check string is all of whitespaces(^ – begin of line, $ – end of line), or check exist one not whitespace character