JSFiddle - React, Tailwind, and code Playground

by Raj Shekhar

HTML

<input class="input" maxlength="10" id="text" type="text" autocomplete="off" />

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) : String.fromCharCode(e.keyCode || e.which);

			if(text.value == '' && !regx.test(e.key)){
           e.preventDefault();
           return false;            
      } else if (!/^[0-9]$/.test(char)) {
	    	return false;
	    }
}