JSFiddle - React, Tailwind, and code Playground

by Raj Shekhar

HTML

<input class="input" maxlength="10" id="text" type="text" autocomplete="off" onkeydown="checkInput(event)"/>

JavaScript

var text = document.getElementById('text');
text.onkeypress = checkInput
text.onpaste = checkInput;
 let regx = /^[6-9]$/;
function checkInput(e) {
    var e = e || event,
    char = e.type == 'keypress' 
        ? String.fromCharCode(e.keyCode || e.which) 
        : (e.clipboardData || window.clipboardData).getData('Text');
        alert(text.value.length)
if(text.value == '' && !regx.test(e.key) && text.length < 2){

                        e.preventDefault();

                        return false;            

                   }
    if (/^[0-9]$/.test(char)) {
    }else{
    return false;
    }
}