This is my input field for phone and i want to validate phone number 1) Only number are allowed 2) Only Upto 10 Digit number are allowed
<input class="form-control" type="text" name="phone" onkeypress='validate(event)'>
and in script file i tried this for only number are allowed,no alphabet are allowed
function validate(evt) {
var theEvent = evt || window.event;
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode( key );
var regex = /[0-9]|\./;
if( !regex.test(key) ) {
if(!regex.test(key) >=10 && !regex.test(key)<=10){
theEvent.returnValue = false;
if(theEvent.preventDefault) theEvent.preventDefault();
}
}
But i need validation for both only number are allowed and upto 10 digit