Whats the best way to test a format validation of lets says a username, with a regex for alphanumeric, but not purely numeric?
I've been using the following validation in my model
validates :username, :format => { :with => /^[a-z0-9]+[-a-z0-9]*[a-z0-9]+$/i }
Numeric username's such as '342' pass the validation, which I don't want.
You want to 'look ahead' for a letter:
/\A(?=.*[a-z])[a-z\d]+\Z/i
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With