怎样验证TextBox输入的全是数字 - .NET技术 / ASP.NET
生活随笔
收集整理的這篇文章主要介紹了
怎样验证TextBox输入的全是数字 - .NET技术 / ASP.NET
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
方法1:
??????????? function?? InputNumb()
??????????? {
//??????????????? debugger;
??????????????? if(?? window.event.keyCode==37)//可輸入Tab
??????????????????? return;
??????????????? if(?? window.event.keyCode==37?? &&?? window.event.keyCode==39)//可輸入左右方向
??????????????????? return;
??????????????? if(?? window.event.keyCode==8?? &&?? window.event.keyCode==46)//可輸入backspace?? del
??????????????????? return;
??????????????? if(?? window.event.keyCode> =96?? &&?? window.event.keyCode <=105?? )//可輸入鍵盤上的數子
??????????????????? return;
??????????????? if(?? window.event.keyCode> =48?? ||?? window.event.keyCode <=57?? )//過濾掉非數字的其他鍵
??????????????????? return;
??????????????? window.event.returnValue?? =?? false;
??????????????? return;
??????????? }
?
方法2:
if(?? window.event.keyCode <48?? ||?? window.event.keyCode> 57?? )
{
??? window.event.returnValue?? =?? false;
??? return;
}
貼子來源飛諾網(http://bbs.firnow.com) 詳細出處參考:http://bbs.firnow.com/dview1t123996.html
??????????? function?? InputNumb()
??????????? {
//??????????????? debugger;
??????????????? if(?? window.event.keyCode==37)//可輸入Tab
??????????????????? return;
??????????????? if(?? window.event.keyCode==37?? &&?? window.event.keyCode==39)//可輸入左右方向
??????????????????? return;
??????????????? if(?? window.event.keyCode==8?? &&?? window.event.keyCode==46)//可輸入backspace?? del
??????????????????? return;
??????????????? if(?? window.event.keyCode> =96?? &&?? window.event.keyCode <=105?? )//可輸入鍵盤上的數子
??????????????????? return;
??????????????? if(?? window.event.keyCode> =48?? ||?? window.event.keyCode <=57?? )//過濾掉非數字的其他鍵
??????????????????? return;
??????????????? window.event.returnValue?? =?? false;
??????????????? return;
??????????? }
?
方法2:
if(?? window.event.keyCode <48?? ||?? window.event.keyCode> 57?? )
{
??? window.event.returnValue?? =?? false;
??? return;
}
貼子來源飛諾網(http://bbs.firnow.com) 詳細出處參考:http://bbs.firnow.com/dview1t123996.html
轉載于:https://www.cnblogs.com/wuhuisheng/archive/2011/04/21/2023268.html
總結
以上是生活随笔為你收集整理的怎样验证TextBox输入的全是数字 - .NET技术 / ASP.NET的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 深入 理解 Statement 和 Pr
- 下一篇: C#中简单的正则表达式(也经常会用到的)