如何验证文本框. [英] how to validate a textbox .

查看:62
本文介绍了如何验证文本框.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


如何验证文本框,如
1)应该只允许数字.
2)小数点后只能输入2位数字.
3)小数点前最多允许输入11位数字,小数点前不能超过11位数字.

任何代码都是最受欢迎的,JavaScript是最受欢迎的........
谢谢,谢谢…………

Hi
How to validate the textbox such that,
1) it should allow only numbers.
2) after decimal only 2 digits are allowed.
3) Maximum of 11 digits are allowed before decimal, the no of digits before decimal must be less than 11 digits.

any code is most welcome , JavaScript is most welcome........
thanks and regards in advance.........

推荐答案

使用AJAX控件工具包的MaskedEditExtender和MaskedEditValidator控件.这是为您的问题提供的最佳,完整的解决方案.
Use AJAX Control Toolkit''s MaskedEditExtender and MaskedEditValidator control. This is the best and Complete Solution for your Question.


您可以为此使用javascript.示例:
You can use javascript for this. Example:
//Javascript function:
function validate()
{
    var txttext=document.getElementById("TextBox1").value;
    var regex=/[0-9][.][0-9]{2}


/; 警报(regex.test(txttext)); }
/; alert(regex.test(txttext)); }





<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="javascript:return validate();"/>


这篇关于如何验证文本框.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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