Sometimes we may want to restrict user from entering more than one URL or prevent entering same words in text input box, with jQuery it is very simple and this snippet below can come in handy in one of those situations.
Notice g modifier at the end of regular expression? that’s because without the g (global search), we will only get 1 match, and here we are searching for multiple string, thus the /g is required at the end.
As you can see in example below — we have a text box, submit button and div element for error output.
Try entering multiple URL below, button should be disabled if it finds more than 1 URL and output the error.