JSFiddle - React, Tailwind, and code Playground
by Daedalus
HTML
<button id="make_controls">Click me to make the field</button>
<div id="field_cont"></div>
JavaScript
$(function () {
$("#make_controls").on("click", function () {
if ($("#address").length === 0) {
$("#field_cont").append('<input type="text" id="address" />\
<button id="button">Disable me by typing in any variant of "PO BOX"</button>');
}
});
$("#field_cont").on("keyup blur", "#address", function () {
var $this = $(this);
if ($this.length > 0) {
if (/p\.?o\.?.*?box/i.test($this.val()) == true) {
$("#button").attr("disabled", "disabled");
$("#address").css("border", "2px solid red");
} else {
$("#button").removeAttr("disabled");
$("#address").css("border", "2px inset");
}
};
});
});