-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathNZL.coffee
43 lines (34 loc) · 1.32 KB
/
NZL.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
Phone = require('../Phone')
PhoneNumber = require('../PhoneNumber')
class NewZealand
constructor: ->
@countryName = "New Zealand"
@countryNameAbbr = "NZL"
@countryCode = '64'
@regex = /^(?:(?:(?:\+|)(?:64|)|))(?:0|)(?:(?:[2][0-9]{7,9})|(?:[3,4,6,7,9][0-9]{7}))$/
@optionalTrunkPrefix = '0'
@nationalNumberSeparator = ' '
@nationalDestinationCode =
["2","3","4","6","7","9"]
@internationalFormatRegex = /^((?:\+|)(64)(?:0|))(\d{0,10})$/
specialRules: (withoutCountryCode, withoutNDC, ndc) =>
phone = new PhoneNumber(@countryNameAbbr, @countryCode, ndc, withoutNDC)
isInternationalFormat = @internationalFormatRegex.test(withoutCountryCode)
if isInternationalFormat
countryCodeRegex = new RegExp "^"+@countryCode+'('+@optionalTrunkPrefix+'|)'
withoutCountryCode = withoutCountryCode.replace(countryCodeRegex, "")
ndc = withoutCountryCode[0]
phone = new PhoneNumber(@countryNameAbbr, @countryCode, ndc, withoutCountryCode.substr 1)
if withoutCountryCode[0] in ['2']
phone.isMobile = true
return phone
else return phone
format: (phone, format) =>
return "(" + @optionalTrunkPrefix + phone.nationalDestinationCode + ") " + phone.number
splitNumber: (number) =>
return [number]
# register
newzealand = new NewZealand()
Phone.countries['64'] = newzealand
# exports
module.exports = newzealand