I want a rails model to exclude certain patterns: runs of two or more spaces.
User.name = "Harry Junior Potter"
is valid, but User.name = "Harry Junior Potter"
is not (two spaces between Harry and Junior).
This to avoid identity theft, where those two names are displayed the same (HTML compresses runs of whitespace).
In other words: Allowed is: [0-9A-z_-]
and '\s
only in series of one'.
My regular-expression is too poor to craft such a regexp, this is what I have (with a negative lookahead, but it does not match correctly.
/([0-9A-z_\-])(\s(?!\s))?/
Note: a before_validation hook already strip()s all the elements, so spaces at begin or end of the string are not a problem.