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 trialSean Perryman
13,810 PointsRegEx Fails
The regular expression that was provided doesn't seem to work; am I using a character incorrectly or something? "The provided regular expression is using multiline anchors (^ or $), which may present a security risk. Did you mean to use \A and \z, or forgot to add the :multiline => true option?"
The notes provided under the video, with the regex being listed at /[a-zA-Z0-9]+/ doesn't validate the profile name properly.
```validates :profile_name, presence: true, uniqueness: true, format: { with: /^[a-zA-Z0-9_-]+$/, message: 'Must be formatted correctly.', }
4 Answers
Sean Perryman
13,810 PointsFound the answer here: https://teamtreehouse.com/forum/confused-with-rails-4-format-validation
/ \A[a-zA-Z0-9_\-]+\z /
Test passes just fine now. (Make sure to remove the spaces above; the code snipped seemed to keep parsing it if I left it in like normal.
Mike Rogers
5,280 PointsI tested it with a online RegEx tool and I had to add brackets to make it match correctly.
validates :profile_name, presence: true, uniqueness: true, format: { with: /^([a-zA-Z0-9_-]+)$/, message: 'Must be formatted correctly.', }
Sean Perryman
13,810 PointsHey Mike, thanks for the quick response. The RegEx you provided is failing in the same manner as the previous one. Entering the expression on regexr.com (EDIT) matches when you enter just one word. They do a good job of explaining what each piece of the expression means, and it all looks to be in order. Not really sure what is going on.
Sean Perryman
13,810 PointsIs it possible I am missing an advanced regex module for ruby or something? Grasping at straws here.