How can I validate that the structure of a url is correct ?, the urls may or may not contain http or https.
For example:
- www.google.com - is valid
- https://www.google.com - is valid
- www.google,com - is invalid
- www.google - is invalid
I try the code of this question:
Validation for URL/Domain using Regex? (Rails)
validates :url_soporte, :url_privacidad, :web_site, :format => {
:with => /^(http|https):\/\/[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}(:[0-9]{1,5})?(\/.*)?$/ix,
:message => 'You provided invalid URL'
}, :allow_blank => true
I get this error:
The provided regular expression is using multiline anchors (^ or $), which may present a security risk. Did you mean to use \A and \z, or forgot to add the :multiline => true option?
and URI.regexp does not work for me
How can i fix this?