# Allegis

### Public/Format-AllegisTelephoneNumber.ps1

 1234567891011121314151617181920212223242526272829303132333435363738394041 Function Format-AllegisTelephoneNumber {      Param([string]\$TelephoneNumber)        #https://en.wikipedia.org/wiki/National_conventions_for_writing_telephone_numbers        \$ProposedTelephoneNumber = \$TelephoneNumber.Replace(" ","").Replace("(0)","")        If(\$ProposedTelephoneNumber.StartsWith("00")){\$ProposedTelephoneNumber = \$ProposedTelephoneNumber.ToCharArray()[2..\$TelephoneNumber.length] -Join ""; \$ProposedTelephoneNumber = "+\$ProposedTelephoneNumber"}        Switch -Regex (\$ProposedTelephoneNumber)        {      '^\+1\d{10}\$' {\$Spaces = @(2,5,8)} #US               '^\d{10}\$' {\$Spaces = @(3,6)}               '^\+441\d{8,9}\$' {\$Spaces = @(3,7)} #UK               '^\+4411\d{8}\$' {\$Spaces = @(3,6,9)}               '^\+441\d{1}?1\d{7}\$' {\$Spaces = @(3,6,9)}               '^\+44(13873|15242|15394|15395|15396|16973|16974|17683|17684|17687|19467)\d{5}\$' {\$Spaces = @(3,8)}               '^\+4416977\d{4,5}\$' {\$Spaces = @(3,8)}               '^\+442\d{9}\$' {\$Spaces = @(3,5,9)}               '^\+443\d{9}\$' {\$Spaces = @(3,6,9)}               '^\+44(5|7)\d{9}\$' {\$Spaces = @(3,7)}               '^\+44800\d{6}\$' {\$Spaces = @(3,6)}               '^\+44(8|9)\d{9}\$' {\$Spaces = @(3,6,9)}               '^\+31\d{9}\$' {\$Spaces = @(3,5,8,10)} #NL               '^\+316\d{8}\$' {\$Spaces = @(3,4,6,8,10)}               '^\+322\d{7}\$' {\$Spaces = @(3,4,7,9)} #BE               '^\+324\d{8}\$' {\$Spaces = @(3,6,8,10)}               '^\+33\d{9}\$' {\$Spaces = @(3,4,6,8,10)} #FR               '^\+41\d{9}\$' {\$Spaces = @(3,5,8,10)}   #CH               '^\+468\d{8}\$' {\$Spaces = @(3,4,7,10)}  #SE               '^\+467\d{8}\$' {\$Spaces = @(3,5,8,10)}               '^\+468-\d{8}\$' {\$Spaces = @(3,8,11)}               '^\+467\d-\d{7}\$' {\$Spaces = @(3,9,11)}               '^\+49\d{5,11}\$' {\$Spaces = @(3)} #DE               '^\+49(30|40|69|89)\d{5,9}\$' {\$Spaces = @(3,5)}               '^\+49800\d{7}\$' {\$Spaces = @(3,6)}               '^\+491(5|6|7)\d{7,9}\$' {\$Spaces = @(3,6)}               '^\+353\d{8}\$' {\$Spaces = @(4,8,10)} #IE               '^\+3538\d{8}\$' {\$Spaces = @(4,6,9)}               '^\+971\d{8}\$' {\$Spaces = @(4,5,8)} #AE               '^\+9715\d{8}\$' {\$Spaces = @(4,6,9)}        }        \$CharArray = \$ProposedTelephoneNumber.ToCharArray()        \$ProposedTelephoneNumber = For(\$y = 0; \$y -lt \$CharArray.Count; \$y++){If(\$Spaces -Contains \$y){" \$(\$CharArray[\$y])"}Else{\$CharArray[\$y]}}        \$ProposedTelephoneNumber -Join "" }