Thứ Tư, 28 tháng 10, 2015

không cho nhập chữ ( only number )

**** script
$(".numberic").keypress(function(e){
//if the letter is not digit then display error and don't type anything
if (e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
//display error message
$("#errmsg").html("Number").show().fadeOut("slow");
return false;
}
});

**** code
<input id="HMobile" class="numberic" type="text" name="mobiphone" value=" ">

===========================================================================
<input type="text" name="txt_phone" onkeypress="return isNumberKey(event)">

****JS:
function isNumberKey(evt){
 var charCode = (evt.which) ? evt.which : event.keyCode
 if (charCode > 31 && (charCode < 48 || charCode > 57))
  return false;
 return true;
}

===========================================================================

<input name="number" onkeyup="if (/\D/g.test(this.value)) this.value = 
this.value.replace(/\D/g,'')" maxlength="10">

===========================================================================
<input name='number' onblur='valid(this,"numbers")' 
onkeyup='valid(this,"numbers")'>

<script type="text/javascript"
function valid(o,w){o.value o.value.replace(valid.r[w],''); 
}valid.r={'numbers':/[^\d]/g}</script> 

Không có nhận xét nào:

Đăng nhận xét