Domain Name Validation Using a Regular Expression


This question already has an answer here:

  • javascript regular expression validation for domain name? 6 answers

I want to validate domain name (only), which is going to be entered into textbox.

Acceptance Criteria:

(anything preceding with http:// or https:// or ftp://)

I have/had tried this:


But it doesn't take: or (that is in my acceptance criteria)

(After that)Also tried this:


This overcome above problem,But it also take like: (that is in my reject criteria)

I am not more good at Regular expressions, so, what will be the regular expression for above scenario. (Any modifications do i need in existing code?)

This solves my problem:

^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})(\/(?:[\/\w \.-]*)*\/?)?([\/?#].*)?

This Article helps.

Edit: Not Working. Also accepting and