JSFiddle - React, Tailwind, and code Playground
HTML
<input type="text" id="num">
<button onclick="myFunction()">submit</button>
<p id="output"></p>
JavaScript
function myFunction() {
num = document.getElementById('num').value;
var $output = document.getElementById("output");
if (num.length < 4) {
$output.innerHTML = '';
return false;
}
var one = num.substring(2, 4); //getting letter at 3rd and 4th position
$output.innerHTML = one;
}
window.onkeypress = function(evt)
{
evt = (evt) ? evt : window.event;
var charCode = (evt.which) ? evt.which : evt.keyCode;
if (charCode >= 32 && (charCode < 48 || charCode > 57)) {
return false;
}
return true;
}