Let’s face it, most of us creating apps collect at a very minimum a name and email address. By a simple validation method to our model, we can easily check the length, format, and presence of our fields. Checking the format of an email address is also simple, but requires a little more work. Using validates_format_of we are able to validate an email address against a regular expression (RegEx).
1 2 3 4 5 | # our User model class User < ActiveRecord::Base validates_presence_of :email validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i end |
Read up on validations at the Rails API
Read up on regular expressions
Add New Comment
Viewing 3 Comments
Thanks. Your comment is awaiting approval by a moderator.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Do you already have an account? Log in and claim this comment.
Add New Comment