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.