From f9b2d960ada42d3aada0e2f95585c8890b4741b8 Mon Sep 17 00:00:00 2001 From: Suman Kundu <32534370+devsumanmdn@users.noreply.github.com> Date: Fri, 22 Jun 2018 16:02:15 +0530 Subject: [PATCH] To add support for indian phone numbers --- src/script/countries/IND.coffee | 41 +++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/script/countries/IND.coffee diff --git a/src/script/countries/IND.coffee b/src/script/countries/IND.coffee new file mode 100644 index 0000000..d0d77ef --- /dev/null +++ b/src/script/countries/IND.coffee @@ -0,0 +1,41 @@ +Phone = require('../Phone') +PhoneNumber = require('../PhoneNumber') + +# For more info check: +# http://www.howtocallabroad.com/bolivia/ +class India + constructor: -> + @countryName = "India" + @countryNameAbbr = "IND" + @countryCode = '91' + @regex = /^(?:(?:(?:\+|)591)|)(?:0|)[23467]\d{7}$/ + @optionalTrunkPrefix = '0' + @nationalNumberSeparator = ' ' + @nationalDestinationCode = ['6', '7', '8', '9', '0'] + + specialRules: (withoutCountryCode, withoutNDC, ndc) => + phone = new PhoneNumber(@countryNameAbbr, @countryCode, ndc, withoutNDC) + + if withoutNDC.length is 10 + if ndc in ['0'] + phone.isMobile = true + phone.nationalDestinationCode = '' + phone.number = withoutCountryCode + else + phone.isMobile = false + return phone + + splitNumber: (number) => + if number.length is 10 + return Phone.compact number.split(/(\d{4})(\d{6})/) + else if number.length is 13 + return Phone.compact number.split(/(\d{3})(\d{4})(\d{6})/) + + return [number] + +# register +india = new India() +Phone.countries['91'] = inida + +# exports +module.exports = india