How can I prevent spaces and tabs in a string field using a validation rule?
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
You can do this with regular expressions. The character class
For more in-depth information on regular expressions I recommend this tutorial that is my primary reference.
As PeterKnolle pointed out in the comments, the correct regular expression should be
I needed to do this in a formula field (which can't use
To use it in a validation rule, you just need to compare the result of this with the original string, if they're different, then the string must contain whitespace.
Note that the second
If you want to prevent that this field remains empty - try this formula: