I want to test my urls validity , which should start with http:// or https:// ,
i ve used this RegExp :
private testIfValidURL(str) {
const pattern = new RegExp('^(https?:\\/\\/)?' + // protocol
'((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|' + // domain name
'((\\d{1,3}\\.){3}\\d{1,3}))' + // OR ip (v4) address
'(\\:\\d+)?(\\/[-a-z\\d%_.~+]*)*' + // port and path
'(\\?[;&a-z\\d%_.~+=-]*)?' + // query string
'(\\#[-a-z\\d_]*)?$', 'i'); // fragment locator
return !!pattern.test(str);
}
This would work , execpt one case :
To consider it as valid , my urls should always start with http://
or https:// , but with my function , urls like www.abcd.com would be treated as valid urls which is not enough for me.
Sugesstions ?