Click here to Skip to main content
15,893,668 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Helloo Experts

I need to validate my password textbox,

This pswd textbox must take only 6 characters and,

this pswd textbox must contain one numeric and 5 alphabets.

Please can you show me how to do this

thanks in @dvance.
Posted

 
Share this answer
 
Hi,

you can make use of regular expressions
refer
7 Regular Expressions a C# Developer Must Know[^]
Using Regular Expressions in C# .NET[^]

try with below expression.
^.*(?=.{6,})(?=.\d)(?=.{5,}[a-z,A-Z]).*$ 


above expression validate for, 1 numeric, 5 alphabets and maximum 6 characters.

hope it helps.
 
Share this answer
 
Comments
Ranjith Reddy CSE 22-Apr-13 6:06am    
boss, this is not working.
As an alternative to regulare expressions. A simple approach would be:
  1. validate length: if password is too short or too long, reject it
  2. validate characters


Further details for point 2:
set num_count = 0, alpha_count = 0, then, for each character of the password, if
  • it is a numeric character, increment num_count
  • it is an alphabetic character, increment alpha_count

at the end of the loop, if num_count is not equal to 1 or alpha_count is not equal to 5 then reject the password.
 
Share this answer
 

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