JSFiddle - React, Tailwind, and code Playground
by John Wick
HTML
<textarea></textarea>
<br/>
<button>Test</button>
<br/>
<div></div>
JavaScript
function isValid(text) {
return /\b(http|https)/.test(text);
}
function isHttp(string) {
if(/(http(s?)):\/\//i.test(string)) {
return true;
}
return false;
}
function isHttp2(url) {
if (!/^(https?:)?\/\//i.test(url)) {
url = 'http://' + url;
}
return url;
}
$("button").click(function() {
if (isHttp($("textarea").val())) {
$("div").text("Valid");
} else {
$("div").text("Invalid");
}
});