JSFiddle - React, Tailwind, and code Playground
by cincodenada
HTML
<form method="POST">
<input name="image" type="text"/>
<input type="submit"/>
</form>
JavaScript
imgSitesValid = /^test$/;
imgSitesList = 'test';
$("form").submit(function() {
if ($('input[name="image"]').val().length > 0) {
if ($('input[name="image"]').val().match(imgSitesValid)) {
alert("1");
return true;
}
else {
if (!$('#img_error').length) {
$('input[name="image"]').addClass('error');
$("<br /><label for=\"title\" id=\"img_error\" class=\"error\">This image host is invalid or not allowed. The following image hosts are allowed: " + imgSitesList + ".</label><br />").insertAfter('input[name=image]');
}
alert("2");
return false;
}
}
else {
alert("3");
return false;
}
return false;
});