I'm using the following to verify if a URL is formatted correctly: / P>
validates_format_of: website ,:with ==> URI :: RJXP (% w (http https))
However, when the URL does not start with http: //
or does not work or https: //
. Are there some similar ways to validate the URL with URI :: regexp
(or URI
) and it is to include a valid URL which is http: //
? (For example, www.google.com
is valid, as is http://www.google.com
)
provides a strong regex:
\ b (([\ w-] +: //? | Www [.]] [^ \ S ()
URL :: regexp is a URI in its definition of loose (although it requires http ...).] + (?: \ ([\ W \ d] + \) | ([^ [: punct:] \ s] | /)) ) Improvement in (NB Newline and Indentation has been added here for clarity, see the post for a more expanded version with explanation): < Code> (? I) \ b ((?: [As] [\ w -] +: (?: / {1,3} | [a-z0- 9%]) | www \ d {0,3} [.] | [A-z0-9]. [-] [[.] [Ed] {2,4} /) (?: [^ \ S ( ) <+ + | \ (([^ \ S ())| + | (\ [[^ \ s ()] ] + \)) * \)) + (?: \ (([^ \ S ()) | + | (\ [[^ \ s ()] ] + \)) * * *] = [^ \ S`! () \ [\] {} :: '., <<> You can use a virtual attribute or filter to add
before_save
to ahttp: //
if necessary On url
No comments:
Post a Comment