Created
August 23, 2012 05:33
-
-
Save sur/3433014 to your computer and use it in GitHub Desktop.
validate formats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'open-uri' | |
class Some < ActiveRecord::Base | |
# validates urls | |
validates :url, :presence => true, :format => /(^$)|(^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(([0-9]{1,5})?\/.*)?$)/ix, | |
:uniqueness => true | |
# validates email | |
validates :email, :uniqueness => true, :presence => true, :format => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment