JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" maxlength="2" />
<a href="#">Validate</a>
JavaScript
$("a").click(function() {
$input = $("input");
console.log($input.attr("maxlength"), $input.val().length);
if ($input.attr("maxlength") != $input.val().length || !/^\d+$/.test($input.val())) {
console.log('failed');
} else {
console.log('passed');
}
return false;
});