如何使用java脚本限制文本框中的数字超过6位数 [英] How to restrict when number is more than 6 digit in text box using java script

查看:125
本文介绍了如何使用java脚本限制文本框中的数字超过6位数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在所有模块的网格中都有文本框。我想,当用户在文本框中输入超过6位数时,不应允许在java脚本中输入超过6位数。 java脚本应该从脚本文件中调用。

解决方案

使用maxLength = 6属性。

例如< input type =textstyle =width:100px; maxlength =6/>


试试这个.. :)



  function  isValidateLen(txtID)
{
txtObj = document .getElementById(txtID);
if (txtObj.value.length< 6
{
返回 true ;
}
其他
{
返回 ;
}
}





 <   asp:textbox     id   =  txtBox   < span class =code-attribute> runat   =  server    width   =  150px    onkeypress   =  javascript:return isValidateLen(this);    xmlns :asp   = #unknown > ;  <   / asp:textbox  >  


Hi,
I have textbox inside the grid in all modules. i want, when user enters more than 6 digit in the textbox,it should not allow to enter more than 6 digit in java script. that java script should call from script file.

解决方案

Use the maxLength=6 attribute.
E.g. <input type="text" style="width:100px;" maxlength="6" />


try this.. :)

function isValidateLen(txtID)
{
txtObj = document.getElementById(txtID);
if(txtObj.value.length < 6)
{
return true;
}
else
{
return false;
}
}



<asp:textbox id="txtBox" runat="server" width="150px" onkeypress="javascript:return isValidateLen(this);" xmlns:asp="#unknown"> </asp:textbox>


这篇关于如何使用java脚本限制文本框中的数字超过6位数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆