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

Breadcrumb

more

Connor and Chris don't just spend all day on AskTOM. You can also catch regular content via Connor's blog and Chris's blog. Or if video is more your thing, check out Connor's latest video and Chris's latest video from their Youtube channels. And of course, keep up to date with AskTOM via the official twitter account.

Question and Answer

Chris Saxon

Thanks for the question, Nikhil.

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

Answered by: Chris Saxon - Last updated: July 07, 2016 - 1:15 pm UTC

Category: Developer - Version: 11g

Viewed 1000+ times

Whilst you are here, check out some content from the AskTom team: RTFM? KISS? Comment? Whatever, just get the code to work right!

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 we 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.

and you rated our response

  (1 rating)

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

Reviews

July 07, 2016 - 1:24 pm UTC

Reviewer: A reader

Thanks a lot Chris!!