Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for at least one numeric char in string 1

Status
Not open for further replies.

sanctified

Programmer
Mar 9, 2006
65
GB
Hi Group,
I have a text box on my login page. As part of the validation, I want to ensure that at least ONE character of the password is numeric. I've had a look at the IsNumeric and Instr Function but can't seem to get the syntax right to check that for AT LEAST ONE character being numeric.

Textbox is called: txtPassword
ANy pointers much appreciated.
 
In this case, try using a RegularExpression Validator. Otherwise you will have to loop through each character of the string and test if it is numeric.
Jim
 
Hi Jim,
Thanks for this. Yes I started to get myself in a muddle as the password could be any length and I was going to test for each character, became a bit lengthy and messy. I'll take a look at the Regular Expression.

Regards
 
This will require at least one digit.

(w+)?\d+(\w+)?
 
[(w+)?\d+(\w+)?]{8,10}

This takes it one more step. This requires the password to be between 8 and 10 characters.

Maybe there is a more elegant method.
 
Hi IT4EVR,
I've tried using what you've suggested however even when I put in a password with a digit the error message for the validator appears.
The validation should pass.

I've placed the validator against the 1st password text box. This is where the user enter their new password. The 2nd password text box is to confirm the text in the 1st password text box.


Thanks
 
The expression should be correct. I tested it out. My second example checks to make sure that the password length is between 8 and 10 characters. You can change that to any range you want or just use the first example if you don't want to check for the password length.
 
Hi IT4EVR
I cut and pasted your code but had a space before the start of the string so this was throwing out the validation.
It works a charm now. Thanks a lot!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top