»
Tiếng AnhTiếng PhápTiếng Việt

In - Chỉ nhập kí số - JavaScriptBank.com

Phiên bản đầy đủ: jsB@nk » Biểu mẫu » Hạn chế » Chỉ nhập kí số
URL: https://www.javascriptbank.com/numbers-restriction.html

Chỉ nhập kí số © JavaScriptBank.comBạn có thể dùng đoạn mã này nếu muốn người dùng chỉ nhập vào các kí số trong vùng nhập liệu nào đó.

Phiên bản đầy đủ: jsB@nk » Biểu mẫu » Hạn chế » Chỉ nhập kí số
URL: https://www.javascriptbank.com/numbers-restriction.html



JavaScript
<script type="text/javascript"><!--// Copyright 1999 Idocs, Inc. http://www.idocs.comfunction numbersonly(myfield, e, dec) {  var key;  var keychar;  if (window.event)    key = window.event.keyCode;  else if (e)    key = e.which;  else    return true;  keychar = String.fromCharCode(key);  // control keys  if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) )    return true;  // numbers  else if ((("0123456789").indexOf(keychar) > -1))    return true;  // decimal point jump  else if (dec && (keychar == ".")) {    myfield.form.elements[dec].focus();    return false;  } else    return false;}//--></script>


HTML
<form>  U.S. Zip Code: <input name="dollar" size="5" maxlength="5" onkeypress="return numbersonly(this, event)">  <input value="Submit" type="button"></form>