In my user model, I have an attribute called ‘nickname’ and validates as such:
validates_format_of :nickname, :with => /[a-zA-Z0-9]$/, :allow_nil => true
However, it is currently letting this string pass as valid:
a?c
I only want to accept alphanumeric strings – does anyone know why my regular expression is failing? If anybody could suggest a better regular expression, I’m all ears.
You need to anchor the pattern on both sides: