RegEx Check password string

G

Guest

Can someone tell me why this is not working. I am trying to test a string to
see if it has a combination of letters and numbers from 7-15 characters long.

Thanks

Public Function CheckPassword(rng As Range) As Variant
Dim reg As Object
'Checks for password with
Set reg = CreateObject("VBScript.RegExp")
With reg
.Pattern = "^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{7,15}$"
CheckPassword = .test(rng.Formula)
End With
End Function
 
T

Tim Williams

EM,

Any reason you're testing the range's Formula instead of the Value ?

Tim
 
T

Tim Williams

Also maybe just try [A-Za-z0-9]{7,15}

Tim


Tim Williams said:
EM,

Any reason you're testing the range's Formula instead of the Value ?

Tim

ExcelMonkey said:
Can someone tell me why this is not working. I am trying to test a
string to
see if it has a combination of letters and numbers from 7-15 characters
long.

Thanks

Public Function CheckPassword(rng As Range) As Variant
Dim reg As Object
'Checks for password with
Set reg = CreateObject("VBScript.RegExp")
With reg
.Pattern = "^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).{7,15}$"
CheckPassword = .test(rng.Formula)
End With
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top