验证文本框 [英] Validation Of TextBox

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

问题描述

你好朋友,
我正在对表单进行验证,我有一个问题.
我必须验证这样的文本框,使其仅接受6到8位之间的字母数字值.
如12345a或asdgfg67
在此先感谢

Hello Friends,
I am doing validation on my form ,i have a problum.
i have to validate a textbox like this that it will take only alphnumeric values in between 6 to 8 digits.
like 12345a or asdgfg67
Thanks In Advance

推荐答案

仅将Ajax的过滤器文本框扩展器用于字母数字,并且对最大值和最小值进行范围验证
Use Filter Textbox Extender of Ajax for only alphanumeric and Range validation for Max and min value
<cc1:FilteredTextBoxExtender ID="txtMobile_FilteredTextBoxExtender"

                 runat="server" Enabled="True" TargetControlID="txtMobile"

                 ValidChars="0123456789abcdefghijklmnopqrstuvwxyz">
             </cc1:FilteredTextBoxExtender>


< asp:TextBox ID ="TextBox1" runat ="server"></asp:TextBox>


<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<asp:RangeValidator ID="RangeValidator1" runat="server"

                ControlToValidate="TextBox1" ErrorMessage="RangeValidator" MaximumValue="8"

                MinimumValue="6"></asp:RangeValidator>


这是Java脚本.希望这项工作有效

函数ValidateAlphaNumeric(ctrlID,ctrlName)
{
var password = document.getElementById(ctrlID).value;

if(密码!=")
{
var checkNumber = 0,checkAlpha = 0;

for(count = 0; count< password.length; count ++)
{
if((password.charAt(count)< ="z" && password.charAt(count)> ="a")||(password.charAt(count)< ="Z" && password.charAt(count )> ="A"))
{
checkAlpha = 1;
}
否则if((password.charAt(count)< ="8" && password.charAt(count)> ="6"))
{
checkNumber = 1;
}
}
}
其他
{
返回true;
}
Here is the Java script..Hope this works

function ValidateAlphaNumeric(ctrlID, ctrlName)
{
var password = document.getElementById(ctrlID).value;

if(password != "")
{
var checkNumber=0,checkAlpha=0;

for(count=0 ; count < password.length ; count++)
{
if((password.charAt(count) <= "z" && password.charAt(count) >= "a") ||(password.charAt(count) <= "Z" && password.charAt(count) >= "A"))
{
checkAlpha = 1;
}
else if((password.charAt(count) <= "8" && password.charAt(count) >= "6"))
{
checkNumber = 1;
}
}
}
else
{
return true;
}


I think when you get the input of password,
first, validate the length between 6-8;
second,validate each char of the input-string, using regular expressions '\w'.
good luck!


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

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