Click here to Skip to main content
14,971,553 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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
Posted
Updated 5-Dec-10 19:16pm
v2

Use Filter Textbox Extender of Ajax for only alphanumeric and Range validation for Max and min value
XML
<cc1:FilteredTextBoxExtender ID="txtMobile_FilteredTextBoxExtender"
                 runat="server" Enabled="True" TargetControlID="txtMobile"
                 ValidChars="0123456789abcdefghijklmnopqrstuvwxyz">
             </cc1:FilteredTextBoxExtender>

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

XML
<asp:RangeValidator ID="RangeValidator1" runat="server"
                ControlToValidate="TextBox1" ErrorMessage="RangeValidator" MaximumValue="8"
                MinimumValue="6"></asp:RangeValidator>
   
v3
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;
}
   
CSS
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!
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900