Micro Focus QTP (UFT) Forums

Full Version: Regular Expression for a Password
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am doing descriptive programming and i need to use Regular Expression for validating a password and the requirement are as follows:
1) Password should contain 8 characters.
2) Fifth character should be numeric.
3) Last 2 characters should be special charactes except % and ^ characters.

Please let me know how to cover this.
Thanks in advance..
Pass the set of different password from the data table of the QTP or from external xls file and use these values in the script as a loop.
Hi Ritesh,
Lets assume ur password: pwd=venk1a;?
You can do validation for this:
1. Password should be 8 characters
Code:
If len(pwd)=8 Then
Pass
Else
Fail
End If

2. To fetch the fiftch character use Mid function
and pass "IsNumeric" function to find whether it is Numeric or Not

3. Right(pwd,1)<> "%" or "^" and Left(Right(pwd,2),1)<> "%" or "^".

Please let me know for further clarification.

Venkat.Batchu
Hi Ritesh,

I'm a bit confused with your requirements

1. The password contains 8 characters, and fifth character should be numeric, so what should the first 4 characters be? Alphabet letters or numeric or special characters?
2. Also, what should the sixth character be?

Anyway, I post my regular expression to solve your problem (hope I got you)

Code:
^\w{4,4}\d\w[!@#$&*()-_=+\{\}\[\]|\\/;:'",.<>`~]{2,2}$

My regular expression will match with the password which has:
- 8 characters in total
- The first 4 characters should be Alphabet letters
- The fifth character should be numeric
- The sixth character should be Alphabet letters
- The last 2 characters should be special character except % and ^ (I added some special characters on keyboard, you can add some more if you want)