All threads / Rails for Beginners Part 12: Validations Discussion

Ask A Question


You’re not receiving notifications from this thread.

Rails for Beginners Part 12: Validations Discussion

I tried copying this regex "\A[@\s]+@[@\s]+\z" to but it aren't working until I remove the \A and \z making this [@\s]+@[@\s]+ before it could work, any reason for that?

I think you might be doing something wrong. It works in my case,


An alternative to using the Regex can be using a built-in Ruby constant

validates :email, format: { with: URI::MailTo::EMAIL_REGEXP, message: 'invalid email address provided' }

Join the discussion

Want to stay up-to-date with Ruby on Rails?

Join 53,406+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.

    logo Created with Sketch.

    Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

    © 2021 GoRails, LLC. All rights reserved.