开发者

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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜