Validation for URL/Domain using Regex? (Rails)

后端 未结 13 1802
野的像风
野的像风 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:50

    I took what you had and modified it so that I could make the http:// or https:// optional:

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

提交回复
热议问题