And here's the one for mobiles:
if (preg_match('/^(?(?=64)(?P<CountryCode>64)|0?)(?!240)(?
P<AreaCode>20|21|22|24|27|280|28|283|2885|29)(?P<PhoneNumber>(?(?<=^64?
(?:22|24|27)|(?:0(?:22|24|27)))[0-9]{7}|[0-9]{6,8}))$/', $subject)) {
# Successful match
} else {
# Match attempt failed
}
Only 022, 024, and 027 are restricted to 7 digit phone number. The
rest are assumed to be 6-8 digits.
Match (M)/No Match (N):
M = 020123456
M = 0201234567
M = 02112345678
N = 021123456789 (021 assumed to have 6-8 digits, this has 9)
M = 20123456
M = 201234567
M = 2112345678
N = 21123456789 (021 assumed to have 6-8 digits, this has 9)
M = 6420123456
M = 64201234567
M = 642012345678
N = 6420123456789 (020 assumes to have 6-8 digits, this has 9)
N = 6422123456 (022 must have 7 digits, this has 6)
M = 64221234567
N = 642212345678 (022 must have 7 digits, this has 8)
N = 6422123456789 (022 must have 7 digits, this has 9)
// no matches, no 23 (023) mobile code
N = 6423123456
N = 64231234567
N = 642312345678
N = 6423123456789
WARNING: these have not been exhaustively tested. Preliminary tests
seem OK, though. Use at your own risk.
Thanks,
David
www.SexWorkers.co.nz (Not Safe For Work)
On Jul 23, 10:47 am, David <[email protected]> wrote:
> Just wanted to share this regular expression that I am working on, in
> case it may be of some use to someone in this forum. The following
> pattern matches NZ land line phone numbers. Pattern based
> onhttp://en.wikipedia.org/wiki/Telephone_numbers_in_New_Zealand#Landlines.
>
> if (preg_match('/^(?(?=64)(?P<CountryCode>64)|0?)((?:(?P<AreaCode>3|4|
> 6|7|9)(?!900|911|999)(?P<PhoneNumber>[2-9][0-9]{6})))$/', $subject)) {
> # Successful match} else {
>
> # Match attempt failed
>
> }
>
> Match:
> 6497891234
> 97891234
> 097891234
>
> No Match:
> 6197891234 (Australia country code)
> 6499001234 (900,911, 999 not valid beginning phone number)
> 64097891234 (there shouldn't be a 0 before the 9 when dialing
> internationally)
> 91891234 (phone number cannot begin with 0 or 1)
> 57891234 (invalid area code)
>
> I'm open to any suggestions for improvement. Regular expression for
> mobile phones next.
>
> Thanks,
> David
> SexWorkers.co.nz (Not Safe For Work)
--~--~---------~--~----~------------~-------~--~----~
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]
-~----------~----~----~----~------~----~------~--~---