+ 1
Please help. How to find that the user entered web address
I'm creating a chat app. if a user enters a web address and submits the message, how to find that the user entered a web address. And if the user entered ordinary message rather than web address how to display it normally. Thanks in advance.
2 Antworten
+ 2
Try this
var str='google.com';
var regex = new RegExp(/[-a-zA-Z0-9@:%_\+.~#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~#?&//=]*)?/gi);
if(regex.test(str))
alert(true);
else
alert(false);
source
https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
0
thanks Kunal Thakur. It's working