文本框仅允许数字 [英] Text Box Allow Only numbers
本文介绍了文本框仅允许数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
i想要一个只允许数字的文本框和另一个只允许字符的文本框..........
请帮助我
Kishore R
Gis Solutions
Hallo
i want a textbox that allow only numbers and another textbox that allow only characters..........
Kindly help me
Kishore R
Gis Solutions
推荐答案
您正在寻找的功能
更多细节阅读文章:增强的文本框控件 [ ^ ]
Function you are looking for
Fore more detail read article : Enhanced Textbox Control[^]
function IntegerAndDecimal(e,obj,isDecimal)
{
if ([e.keyCode||e.which]==8) //this is to allow backspace
return true;
if ([e.keyCode||e.which]==46) //this is to allow decimal point
{
if(isDecimal=='true')
{
var val = obj.value;
if(val.indexOf(".") > -1)
{
e.returnValue = false;
return false;
}
return true;
}
else
{
e.returnValue = false;
return false;
}
}
if ([e.keyCode||e.which] < 48 || [e.keyCode||e.which] > 57)
e.preventDefault? e.preventDefault() : e.returnValue = false;
}
您好,
此脚本可用于验证您的表单对于数值。 Numeric TextBox仅允许数字并接受一个小数点。
Hi,
This Script can be used to validate your form for numeric values. The Numeric TextBox allows only numbers and accepts one decimal Point.
<script language=javascript>
function keyCheck(eventObj, obj)
{
var keyCode
// Check For Browser Type
if (document.all){
keyCode=eventObj.keyCode
}
else{
keyCode=eventObj.which
}
var str=obj.value
if(keyCode==46){
if (str.indexOf(".")>0){
return false
}
}
if((keyCode<48 || keyCode >58) && (keyCode != 46)){ // Allow only integers and decimal points
return false
}
return true
}
</script>
<asp:TextBox ID="txtNumeric" runat="server" onkeypress = "return keyCheck(event, this);"
onpaste = "return false;"></asp:TextBox>
您还可以为文本框仅接受int值和字母。
You can also create a mask for the textbox to accept int values and alphabets only.
这篇关于文本框仅允许数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文