Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

General Discussion

Cant get validate probile_name to work.

validates :profile_name, format: { with: /a-zA-Z-_+/, message: "must be formatted correctly." }

I use this code but everytime i try and make a profile name no matter what I put it will still tell me it is not formated corectly.

4 Answers

Did you mean:

/a-zA-Z-+/ ?

It might be treating the - between Z and \ as a 'range'.

Try escaping the - with \ to get \- and see if that is the cause?

I am having the same issue:

validates :profile_name, presence: true, uniqueness: true, format: { with: /a-zA-Z0-9_-/, message: 'Must be formatted correctly.' }

user.profile_name = "My Profile with Spaces"
assert user.errors[:profile_name].include?("Must be Formatted Correctly")

This assertion still fails

I think he does try to fix it in a later video from what I can remember I have only just come back to this project so if I found out how to do it ill let you know.

Use this code instead for the keyspace

/\A[a-zA-Z0-9_-]+\Z/