JSFiddle - React, Tailwind, and code Playground
HTML
<p>Type some integers separated by commas, spaces, newlines, etc.</p>
<textarea id="text"></textarea>
<p id="results">IDs found will go here once you start typing.</p>
CSS
textarea {
width: 100%;
height: 150px;
}
JavaScript
var textarea=$("#text");
$.each(["keydown", "keyup", "change"], function(i, ev) {
textarea.bind(ev, function() {
parse();
});
});
parse();
function parse() {
var text=textarea.val();
var results=$.map(text.split(/[^\d]+/), function(item) {
var num=parseInt(item, 10);
if(isNaN(num)) {
return null;
}
return num;
});
$("#results").text(JSON.stringify(results));
}