如何在php中的文本框上应用数字验证? [英] how to apply number validation on textbox in php?
本文介绍了如何在php中的文本框上应用数字验证?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
i有一个文本框,我想通过这个文本框只接受数字。
< body >
< 表格 方法 = POST action = < span class =code-keyword> >
电话号码 - < 输入 type = 数字 < span class =code-attribute> name = phone no maxlength = 10 / >
< / form >
< / body >
plz help ...
解决方案
试试这个
函数is_numeric(12);
试试这个javascript函数:
函数掩码(textbox,e){
var charCode =(e.which)? e.which:e.keyCode;
if(charCode == 46 || charCode> 31&&(charCode< 48 || charCode> 57))
{
alert(Only Numberseded);
返回false;
}
其他
{
返回true;
}
}
在文本框中调用这样的函数,
onkeypress = 返回掩码(this,event);
Javascript代码:
函数allnumeric(inputtxt)
{
var numbers = / ^ [0-9] +
dear sir,
i have one textbox and i want to do accept only numbers through this textbox.
<body>
<form method="POST" action="">
Phone no-<input type="number" name="phone no" maxlength="10"/>
</form>
</body>
plz help...
解决方案
try this
functionis_numeric(12);
try this javascript function:
function mask(textbox, e) { var charCode = (e.which) ? e.which : e.keyCode; if (charCode == 46 || charCode > 31&& (charCode < 48 || charCode > 57)) { alert("Only Numbers Allowed"); return false; } else { return true; } }
Call function like this in textbox,
onkeypress="return mask(this,event);"
Javascript Code:
function allnumeric(inputtxt)
{
var numbers = /^[0-9]+
这篇关于如何在php中的文本框上应用数字验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文