Skip to content

Instantly share code, notes, and snippets.

@sur
Created August 23, 2012 05:33
Show Gist options
  • Save sur/3433014 to your computer and use it in GitHub Desktop.
Save sur/3433014 to your computer and use it in GitHub Desktop.
validate formats
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