0

I need a regex to be able to validate a domain name without http:// or https://

What I mean:

Valid Should Be:

domain.com
domain.fr
domain.it
domain.whateverelse
subdomain.domain.com
subdomain.doamin.fr
subdomain.domain.whateverelse

Invalid Should Be:

domain
http://domain.com
https://domain.com
https://domain.whateverelse
http://subdomain.domain.com
http://subdomain.domain.fr
http://subdomain.domain.whateverelse

This is what I came so far:

(http(s)?://)?([\w-]+\.)+[\w-]+[.com]+(/[/?%&=]*)?

For example the regex above considers domain.whatever as invalid ... so basically works just with .com

David Dury
  • 5,537
  • 12
  • 56
  • 94

1 Answers1

0

This one look realy good:

(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?

Is comming from: http://regexlib.com/REDetails.aspx?regexp_id=96 Where can find a lot more ;)

Rene M.
  • 2,660
  • 15
  • 24