Skip to content

To add support for indian phone numbers #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/script/countries/IND.coffee
Original file line number Diff line number Diff line change
@@ -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