I am working on 1 project and there is 1 form in it where i need validation with appropriate message if validation fails
validation is for format check. I need to check if user enter words with more than 1 space character in it. i mean
if user enter
"hello world"
then it should show “invalid format”. The correct format should be
"hello world"
I mean only 1 space character is allowed.
I have tried this
validates_format_of :name, :with => /\s/
but it shows error when there is no space character….
Try this:
Note that
\smatches any whitespace characters, which includes newlines, tabs, etc. as well as spaces. If you just want to match two or more spaces (and not two or more whitespace characters), then this would be better: