ruby on rails - Devise validation constantly failing on sign up -


making simple ruby on rails app practise requires user sign up.

everything works until implement regex validation on 'profile_name' field

here's 'user' model:

validates :profile_name, presence: true,                            uniqueness: true,                            format: {                             with: /^a-za-z0-9_-$/,                             message: 'must formatted correctly.'                            }    

and yet profile name 'jon' refuses pass. error coming from, other 'user' model?

you need add brackets around ranges regex matches "any of range" rather "all of range in order". put + on end allow match in range more once. need change beginning , ending of lines beginning , ending of strings!

validates :profile_name, presence: true,                          uniqueness: true,                          format: {                            with: /\a[a-za-z0-9_-]+\z/,                            message: 'must formatted correctly.'                          } 

details:

\a # beginning of string (not line!) \z # end of string [...] # match within brackets + # match preceding element 1 or more times 

really useful resource generating , checking regex: http://www.myezapp.com/apps/dev/regexp/show.ws


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -