文本框仅接受一个点(.),数字,bacspace和删除按钮 [英] textbox accepts only one dot(.), digit, bacspace and delete button working
本文介绍了文本框仅接受一个点(.),数字,bacspace和删除按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个应用程序,我要在其中验证仅接受单个点(.),数字和退格键以及删除按钮的文本框.请帮助我做到这一点.我急着用.
I am developing an application where i want to validate the textbox which can accept only single dot(.), digits, and backspace and delete button. please help me to do this. i need this in hurry.
推荐答案
朋友,
Friend,
function onlyNumbers(evt)
{
var e = event || evt; // for trans-browser compatibility
var charCode = e.which || e.keyCode;
if (charCode ==8 || charCode ==46 || charCode < 48 || charCode > 57 || charCode ==190)
{
return true;
}
else
{
return false;
}
}
参考
http://www.aspdotnetfaq.com/Faq/What-is-the-the-list-of-KeyCodes-for-JavaScript-KeyDown-KeyPress-and-KeyUp-events.aspx [
Reference
http://www.aspdotnetfaq.com/Faq/What-is-the-list-of-KeyCodes-for-JavaScript-KeyDown-KeyPress-and-KeyUp-events.aspx[^]
If useful accept and vote!!
Regards,
Karthik.J
这篇关于文本框仅接受一个点(.),数字,bacspace和删除按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文