Last active
December 25, 2015 03:59
-
-
Save adammcarth/6913977 to your computer and use it in GitHub Desktop.
Validate website url
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
class Comment < ActiveModel::Base | |
validate :valid_url?, :allow_blank => true | |
def valid_url? | |
if (self.website).start_with?("http://", "https://") and (self.website).end_with?(".*") | |
return true | |
elsif (self.website).end_with?(".*") | |
return true | |
self.website = "http://#{self.website}" | |
else | |
return self.errors[:website] << "The website you entered (#{self.website}) is invalid. Please try again." | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment