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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

RegExp for Postcode not working

Status
Not open for further replies.

pandapark

Technical User
Jan 29, 2003
92
0
0
GB
Hi

I've got my RegExp set up as below - Password and email seem ok but Postcode doesn't seem to work
it will allow

CH1 2HSSSSSSSSSSSSSSSSSSSS
won't allow
CH1 2HS (which is valid)

any ideas ?
thanks
kim

Dim valid_str
Dim oRegExp
Set oRegExp = New RegExp
oRegExp.IgnoreCase = False
oRegExp.pattern = valid_str
Dim matches, match
Set matches = oRegExp.Execute(Password)
For Each match in matches
If len(Password) < 8 Or len(Password) > 15 Then
ErrorMsg1 = ErrorMsg1 & "Password length must be between 8-15 characters<br>"
Else
oRegExp.pattern = "([^a-z0-9])"
If oRegExp.Test(Password) Then
ErrorMsg1 = ErrorMsg1 & "Password contains invalid characters<br>"
Else
oRegExp.pattern = "(^[^a-z]+$)|(^[^0-9]+$)"
If oRegExp.Test(Password) Then
ErrorMsg1 = ErrorMsg1 & "Password must contain at least one lowercase letter, and one number<br>"
Else
end if
End If
End If
Next

Dim valid_str1
valid_str1 = "^[\w-_\.]+\@[\w-_]+(\.[\w-_]+)+$"
Dim oRegExp1
Set oRegExp1 = New RegExp
oRegExp1.pattern = valid_str1
If not oRegExp1.Test(EmailAddr) Then
ErrorMsg1 = ErrorMsg1 & "Email format must be in host@domain.com format<br>"
Else
End If

Dim valid_str2
valid_str2 = "^[A-Z]{1,2}[1-9][0-9]{0,1}[1-9][ABD-HJLNP-UW-Z]{2}$"
Dim oRegExp2
Set oRegExp2 = New RegExp
oRegExp2.pattern = valid_str2
If not oRegExp2.Test(PostCode) Then
ErrorMsg1 = ErrorMsg1 & "Postcode must be in UK format<br>"
Else
 
I dont know if this helps but you may want to try the expression:

^(((([A-PR-UWYZ][0-9][0-9A-HJKS-UW]?)|([A-PR-UWYZ][A-HK-Y][0-9][0-9ABEHMNPRV-Y]?))\s{0,2}[0-9]([ABD-
HJLNP-UW-Z]{2}))|(GIR\s{0,2}0AA))$


Its what i always use (from regexlib.com) and seems to work for me.
 
cheers shatch

works a treat - I'd been on regexlib.com myself but must have missed that one
I thought the way I'd scripted it must be wrong

thanks
kim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top