Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the validation that only accepts lower case 'a-z' and number '0-9'

I have my app and it has username column. For user input, I'd like to make this column with validation.

username has to contain only the characters below

abcdefghijklmnopqrstuvwxyz0123456789
like image 717
MKK Avatar asked Jul 21 '12 13:07

MKK


1 Answers

Use a format validator:

validates :username, format: { with: /\A[a-z0-9]+\z/ }

https://guides.rubyonrails.org/v3.2/active_record_validations_callbacks.html

like image 85
shuriu Avatar answered Oct 06 '22 06:10

shuriu