เขียนไว้นานแล้ว เอาไว้สำหรับตรวจสอบ text box ให้ป้อนข้อมูลเป็นตัวเลขเท่านั้น
เอาตรงนี้ไปใส่ไว้ใน <head> ก่อน
function numbersonly(e){
var unicode=e.charCode? e.charCode : e.keyCode;
if (unicode!=8){
if(unicode<48 || unicode>57){
return false
}
}
}
ตอนใช้งานก็เขียนแบบนี้
<input type=”text” onKeyPress=”return numbersonly(event)” />
สามารถใช้กับ type อื่นๆ เช่น number หรือ tel ก็ได้นะครับ html5 มี type ของ textbox เพิ่มขึ้นเยอะเลย