You need to create a regular expression to validate the URL.

My code is:

var regForURL = /((http(s)?):\/\/)?[a-zA-Z\d@:%._\+~#=]{2,}[^-]\.[az]{2,}([-a-zA-Z\d@:%_\+.~#?&//=]*)/i; var wrongURL_0 = 'http://www.domain-.com'; console.log('Is URL correct?\n1)' + regForURL.test(wrongURL_0)); 

This URL should be false because the dash precedes the dot, but it is true.

  • What language? Is that js? - nick_gabpe
  • Yes js. Sorry for not writing ( - Slava

1 answer 1

It is working. Just parse a little not as you expect.

 [a-zA-Z\d@:%._\+~#=]{2,} парсит две первые ww [^-] парсит третью w (все законно). а дальше есть точка... 

In addition, your expression may parse absolutely invalid url, for example, http://@@@@@:@:@:@:.domain.com .