How do you validate against more than one regex?
I have this validation:
validates :url, :uniqueness => true,
:format => { :with => /^(http:\/\/)?(www\.)?youtube\.com\/watch\?v=([开发者_如何学编程a-zA-Z0-9_-]*)/}
I want to let url
match either the regex above or another regex. How do I add this second regex?
You put both regexes into one regex using the 'bar' operator which does an 'or' for you:
/(^(http:\/\/)?(www\.)?youtube\.com\/watch\?v=([a-zA-Z0-9_-]*)|helloworld)/
Matches a URL or a string containing "helloworld"
精彩评论