Validation for URL/Domain using Regex? (Rails)

后端 未结 13 1774
野的像风
野的像风 2020-11-29 21:10

I am trying to create a validation that checks to make sure a domain/url is valid for example \"test.com\"

def valid_domain_name?
  domain_name = domain.spli         


        
13条回答
  •  既然无缘
    2020-11-29 21:40

    Stumbled on this:

    validates_format_of :domain_name, :with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix
    

    FYI: Rubular is a fantastic resource for testing your Ruby regular expressions

提交回复
热议问题