Skip to Main Content
  • Questions
  • Website validation using regexp_like.

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Nikhil.

Asked: July 07, 2016 - 11:50 am UTC

Last updated: July 07, 2016 - 1:15 pm UTC

Version: 11g

Viewed 1000+ times

You Asked

Hi,

Could you please help to get website validation query using regexp_like.

e.g.
www.google.com
https//:www.google.com both should get validated.

Thanks in advance.

and Chris said...

The following regex will validate the top-level domain and whether it has http(s):// or not:
^(http(s)*://)*[a-z0-9.-]+$

Plug it to regexp_like and you get:
with urls as (
  select 'www.oracle.com' u from dual union all
  select 'http://www.oracle.com' u from dual union all
  select 'https://www.oracle.com' u from dual union all
  select 'https://www.oracle-here.com' u from dual union all
 select 'https://www.####.com' u from dual union all
  select 'not an URL' u from dual union all
  select 'http://' u from dual 
)
  select * from urls
  where  regexp_like(u, '^(http(s)*://)*[a-z0-9.-]+$');

U                         
---------------------------
www.oracle.com             
http://www.oracle.com      
https://www.oracle.com     
https://www.oracle-here.com


But this is basic. It only checks the top-level domain. Checking that a string is a valid URL is complicated:

http://stackoverflow.com/a/190405/1485955

Unless there's a pressing need to ensure that these are real URLs, writing a regular expression is probably more hassle than it's worth.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

A reader, July 07, 2016 - 1:24 pm UTC

Thanks a lot Chris!!

More to Explore

Security

All of the vital components for a secure database are covered in the Security guide.