I’d like ask if there’s a way to validate a string as an url or email at the same time?
for example:
validates_format_of :string, :with => [url_regex, email_regex]
string = 'http://domain.com' => valid
string = 'email@domain.com' => valid
thanks in advance!
According to the Rails API you cannot pass two regexes in an array or something. The solution would be to create a regex that matches both URL’s and email addresses or – as Naveed suggests – create a custom validation. That being said, I don’t think you can validate a URL with a regex.