none
How do I create a UK phone format without using code but with the phone number formats? RRS feed

  • Question

  • I've tried but I can't get an ordinary 4 digit std code and 6 digit number to be formatted correctly.
    Gadya
    Sunday, September 4, 2011 8:40 PM

Answers

  • Spaces in phone numbers tell a lot about what type of phone number it is and for what country or countries the phone number could be from.

    In your first screen shot, the number 01865762192 matches the 4th pattern in the dialog and is then displayed with the 2nd pattern. Maybe you did not intend for it to match the CAAANNNNNNN pattern.

    I would suggest removing all non-UK patterns (which would be all of them except for the 1st) and only add the UK patterns that you would like to accept. I'm more than willing to help you figure out what those patterns are if you can't quite get it right.


    Justin Anderson, LightSwitch Development Team
    Tuesday, September 6, 2011 9:04 PM
    Moderator
  • We do use brackets in the UK. They should be put round the area code to show that dialling it is optional if you are dialling from the same area code.

    Phone numbers should be entered with at least a space between the area code and the subscriber number so that the formatting knows which is which.

    However, LightSwitch's phone number validation is seriously deficient and, in my opinion, not worth using. We build our own based on regular expressions which converts any entry into full E164 (International) format. We did this so that numbers entered  through a LightSwitch application to a SQL Server database could be published through SharePoint and synchronised with Outlook and the users mobile phones and so were dialable from anywhere on the planet. (Not something you can do using LightSwitch's phone number validation.)


    Simon Jones
    • Marked as answer by gadya Friday, September 9, 2011 5:40 PM
    Friday, September 9, 2011 4:43 PM
  • Here's the phone number validation code we use.

    • 44 is the country code for the UK
    • 1646 is our local area code
    • E164 format strips the initial 0 from the number and replaces it with "+" and the country code.
    • This was designed for the UK but could be adapted for other countries by changing the regular expressions.
    • I'm sure there will be quite a few anomalies that aren't catered for.
    • Feel free to convert it to C# yourself.
        Friend Sub ValidatePhoneNumber(ByRef PhoneNumber As StringByVal FieldName As StringByRef Results As EntityValidationResultsBuilder)
            Static rgxLocal As New Regex("^([2-8]\d{5})$"RegexOptions.IgnoreCase)
            Static rgxNational As New Regex("^\(?(0)(\d{2,5})\)?[\s?\-](\d{3,8})([\)?\s?\-])?(\d{4,8})?$"RegexOptions.IgnoreCase)
            Static rgxInternational As New Regex("^(\+|00)[\s\-]?(\d{1,3})[\s\-]?\(?(0)?\)?\s?(\d{1,5})\)?[\s\-]?(\d{2,8})[\s\-]?(\d{2,8})?[\s\-]?(\d{2,8})?$"RegexOptions.IgnoreCase)
     
            If String.IsNullOrWhiteSpace(PhoneNumber) Then
                PhoneNumber = Nothing
            Else
     
                If rgxLocal.IsMatch(PhoneNumber) Then
                    PhoneNumber = String.Format("+44 (1646) {0}", PhoneNumber)
                ElseIf rgxNational.IsMatch(PhoneNumber) Then
     
                    With rgxNational.Matches(PhoneNumber)(0)
                        PhoneNumber = String.Format("+44 ({0}) {1} {2}", .Groups(2).Value, .Groups(3).Value, .Groups(5).Value).Trim
                    End With
     
                ElseIf rgxInternational.IsMatch(PhoneNumber) Then
     
                    With rgxInternational.Matches(PhoneNumber)(0)
                        PhoneNumber = String.Format("+{0} ({1}) {2} {3} {4}", .Groups(2).Value, .Groups(4).Value, .Groups(5).Value, .Groups(6).Value, .Groups(7).Value).Trim
                    End With
     
                Else
                        Results.AddPropertyError(String.Format("Invalid {0} Number - Unable to interpret country code, area code and subscriber number.", FieldName))
                End If
     
            End If
     
        End Sub

    Simon Jones
    • Marked as answer by gadya Friday, September 9, 2011 5:46 PM
    Friday, September 9, 2011 4:56 PM
  • The UK uses a range of number lengths and formats.

    NSN is National Significant Number. This is all of the digits after the 0 trunk code or +44 country code.

    This list covers most of the options for the UK (listed in national format):

     

    7 digit NSNs

    • 0800 1111
    • 0845 46 47

     

    9 digit NSNs

    • (016977) 2xxx
    • (016977) 3xxx
    • (01xxx) xxxxx
    • 0500 xxxxxx
    • 0800 xxxxxx

     

    10 digit NSNs

    • (013873) xxxxx
    • (015242) xxxxx
    • (015394) xxxxx
    • (015395) xxxxx
    • (015396) xxxxx
    • (016973) xxxxx
    • (016974) xxxxx
    • (016977) xxxxx
    • (017683) xxxxx
    • (017684) xxxxx
    • (017687) xxxxx
    • (019467) xxxxx
    • (011x) xxx xxxx
    • (01x1) xxx xxxx
    • (01xxx) xxxxxx
    • (02x) xxxx xxxx
    • 03xx xxx xxxx
    • 055 xxxx xxxx
    • 056 xxxx xxxx
    • 070 xxxx xxxx
    • 07624 xxxxxx
    • 076 xxxx xxxx
    • 07xxx xxxxxx
    • 08xx xxx xxxx
    • 09xx xxx xxxx

     

    Valid formats for geographic numbers include 2+8, 3+7, 4+6, 4+5, 5+5 and 5+4 (and 0+10 for NDO numbers).

    Non-geographic numbers mostly use 0+10 format, but some 0800 numbers and all 0500 numbers use 0+9 format.

    Most code found on the web caters for only a few of these, not the full set.

    The international format adds +44 and a space before the NSN digits.

    The national format adds the 0 trunk code before the NSN digits. For 01 and 02 numbers the area code should be in parentheses, except for NDO numbers (NDO numbers are those where subscriber number begins 0 or 1).

    NDO numbers are National Dialling Only. These have been around for several decades and need the area code to be dialled even when called locally from within the same area. These numbers are used for alarm systems, computer communication systems and other lines that are not dialled for voice calls. They are also used as the termination point for non-geographic numbers. NDO numbers are not supposed to be advertised nor directly called by subscribers. NDO numbers are always 0+10 format.

    There are proposals to open up the NDO ranges in some areas for use by normal subscribers starting some time in 2012.

    • Edited by lesset Monday, October 17, 2011 7:34 AM
    • Marked as answer by gadya Tuesday, October 18, 2011 2:59 PM
    Saturday, October 15, 2011 6:03 PM
    1. you might explain that NSN=National Significant Number and is just the whole phone number without the initial zero or +44.
    2. NDO numbers are new and experimental being trialled in just a couple of areas where they are running short of numbers. I'm not sure what NDO stands for but they force everyone in the area to dial the area code as well as the subscriber's number for all calls even if the area code is the same as that of the phone you are calling from. BT and Ofcom think this is less confusing than having two different area codes for the same town. I would disagree.

    Simon Jones
    • Marked as answer by gadya Tuesday, October 18, 2011 2:59 PM
    Saturday, October 15, 2011 11:02 PM
  • 1.  That text was already there, under the list.

      "The international format adds +44 and a space before the NSN digits."

      "The national format adds the 0 trunk code before the NSN digits."

    2. NDO numbers have been around for decades. I have now added some stuff about that in the answer above. There are now some proposals to use NDO numbers for normal subscribers. They have been used for other purposes for decades; and will continue to be used for those other purposes too.

    This is a useful page about NDO numbers: 

    http://www.aa-asterisk.org.uk/index.php/NDO

    • Edited by lesset Monday, October 17, 2011 7:35 AM
    • Marked as answer by gadya Tuesday, October 18, 2011 2:59 PM
    Sunday, October 16, 2011 6:43 AM
  • That other thread [ http://social.msdn.microsoft.com/Forums/en-US/lightswitchgeneral/thread/76498bca-30b7-4c68-9728-7069b93f2b6e - now closed ] lists these formats:

    (AAA) NNNNNNNN
    (AAAAA) NNNNNN
    +CC (AA) NNNNNNNN
    +CC (AAAA) NNNNNN

    Those are the national format and the international format for 2+8 and 4+6 format numbers. However, the placement of the 0 trunk code should be further clarified, and parentheses are NOT valid in the international format:

    (0AA)  NNNN NNNN
    (0AAAA)  NNNNNN
    +CC  AA  NNNN NNNN
    +CC  AAAA  NNNNNN

    The UK also uses 3+7, 4+5, 5+5 and 5+4 format for geographic numbers, as well as 0+10 for NDO numbers and 0+10 and 0+9 format for non-geographic numbers.

    There's a list of area codes using formats other than 2+8 and 4+6 here:

    http://www.aa-asterisk.org.uk/index.php/01_numbers


    • Edited by lesset Monday, October 17, 2011 7:31 AM
    • Marked as answer by gadya Tuesday, October 18, 2011 2:59 PM
    Sunday, October 16, 2011 6:53 AM

All replies

  • Hi Gadya,

    Simon's answer in the thread below gives the following examples of UK formats.

    http://social.msdn.microsoft.com/Forums/en-US/lightswitchgeneral/thread/76498bca-30b7-4c68-9728-7069b93f2b6e

    (AAA) NNNNNNNN
    (AAAAA) NNNNNN
    +CC (AA) NNNNNNNN
    +CC (AAAA) NNNNNN

    Tim

     

    Sunday, September 4, 2011 8:56 PM
  •  I used the (AAAAA) NNNNNN format.

    If I don't enter the brackets then I get a very strange display.

    If  I enter the brackets. It displays the brackets which we don't use in the UK. 


    Gadya
    Sunday, September 4, 2011 9:24 PM
  • Spaces in phone numbers tell a lot about what type of phone number it is and for what country or countries the phone number could be from.

    In your first screen shot, the number 01865762192 matches the 4th pattern in the dialog and is then displayed with the 2nd pattern. Maybe you did not intend for it to match the CAAANNNNNNN pattern.

    I would suggest removing all non-UK patterns (which would be all of them except for the 1st) and only add the UK patterns that you would like to accept. I'm more than willing to help you figure out what those patterns are if you can't quite get it right.


    Justin Anderson, LightSwitch Development Team
    Tuesday, September 6, 2011 9:04 PM
    Moderator
  • We do use brackets in the UK. They should be put round the area code to show that dialling it is optional if you are dialling from the same area code.

    Phone numbers should be entered with at least a space between the area code and the subscriber number so that the formatting knows which is which.

    However, LightSwitch's phone number validation is seriously deficient and, in my opinion, not worth using. We build our own based on regular expressions which converts any entry into full E164 (International) format. We did this so that numbers entered  through a LightSwitch application to a SQL Server database could be published through SharePoint and synchronised with Outlook and the users mobile phones and so were dialable from anywhere on the planet. (Not something you can do using LightSwitch's phone number validation.)


    Simon Jones
    • Marked as answer by gadya Friday, September 9, 2011 5:40 PM
    Friday, September 9, 2011 4:43 PM
  • Here's the phone number validation code we use.

    • 44 is the country code for the UK
    • 1646 is our local area code
    • E164 format strips the initial 0 from the number and replaces it with "+" and the country code.
    • This was designed for the UK but could be adapted for other countries by changing the regular expressions.
    • I'm sure there will be quite a few anomalies that aren't catered for.
    • Feel free to convert it to C# yourself.
        Friend Sub ValidatePhoneNumber(ByRef PhoneNumber As StringByVal FieldName As StringByRef Results As EntityValidationResultsBuilder)
            Static rgxLocal As New Regex("^([2-8]\d{5})$"RegexOptions.IgnoreCase)
            Static rgxNational As New Regex("^\(?(0)(\d{2,5})\)?[\s?\-](\d{3,8})([\)?\s?\-])?(\d{4,8})?$"RegexOptions.IgnoreCase)
            Static rgxInternational As New Regex("^(\+|00)[\s\-]?(\d{1,3})[\s\-]?\(?(0)?\)?\s?(\d{1,5})\)?[\s\-]?(\d{2,8})[\s\-]?(\d{2,8})?[\s\-]?(\d{2,8})?$"RegexOptions.IgnoreCase)
     
            If String.IsNullOrWhiteSpace(PhoneNumber) Then
                PhoneNumber = Nothing
            Else
     
                If rgxLocal.IsMatch(PhoneNumber) Then
                    PhoneNumber = String.Format("+44 (1646) {0}", PhoneNumber)
                ElseIf rgxNational.IsMatch(PhoneNumber) Then
     
                    With rgxNational.Matches(PhoneNumber)(0)
                        PhoneNumber = String.Format("+44 ({0}) {1} {2}", .Groups(2).Value, .Groups(3).Value, .Groups(5).Value).Trim
                    End With
     
                ElseIf rgxInternational.IsMatch(PhoneNumber) Then
     
                    With rgxInternational.Matches(PhoneNumber)(0)
                        PhoneNumber = String.Format("+{0} ({1}) {2} {3} {4}", .Groups(2).Value, .Groups(4).Value, .Groups(5).Value, .Groups(6).Value, .Groups(7).Value).Trim
                    End With
     
                Else
                        Results.AddPropertyError(String.Format("Invalid {0} Number - Unable to interpret country code, area code and subscriber number.", FieldName))
                End If
     
            End If
     
        End Sub

    Simon Jones
    • Marked as answer by gadya Friday, September 9, 2011 5:46 PM
    Friday, September 9, 2011 4:56 PM
  • Thanks Simon for your very full response and for the code.

    You write: LightSwitch's phone number validation is seriously deficient and, in my opinion, not worth using. 

    Being not very intuitive I found that the phone number validation procedure was not explained to me. I didn't find suitable examples within Lightswitch or within the videos.


    Gadya
    Friday, September 9, 2011 5:53 PM
  • You are right that it is inadequately explained. It is also very US-centric with only minimal thought to internationalization. Having to enter multiple different possible formats on every phone number field in an application is time-consuming and prone to error. Errors that are not easy to spot when they occur.

    The formats themselves are also far too simplistic, hence us coding our validation using regular expressions. The only thing our validation doesn't do is present a breakout box parsing the number into different sections. Not a great loss as far as the users were concerned. They like the regular E164 presentation better as it standardises the layout and makes the numbers dialable from their mobile phones.


    Simon Jones
    Friday, September 9, 2011 10:13 PM
  • The UK uses a range of number lengths and formats.

    NSN is National Significant Number. This is all of the digits after the 0 trunk code or +44 country code.

    This list covers most of the options for the UK (listed in national format):

     

    7 digit NSNs

    • 0800 1111
    • 0845 46 47

     

    9 digit NSNs

    • (016977) 2xxx
    • (016977) 3xxx
    • (01xxx) xxxxx
    • 0500 xxxxxx
    • 0800 xxxxxx

     

    10 digit NSNs

    • (013873) xxxxx
    • (015242) xxxxx
    • (015394) xxxxx
    • (015395) xxxxx
    • (015396) xxxxx
    • (016973) xxxxx
    • (016974) xxxxx
    • (016977) xxxxx
    • (017683) xxxxx
    • (017684) xxxxx
    • (017687) xxxxx
    • (019467) xxxxx
    • (011x) xxx xxxx
    • (01x1) xxx xxxx
    • (01xxx) xxxxxx
    • (02x) xxxx xxxx
    • 03xx xxx xxxx
    • 055 xxxx xxxx
    • 056 xxxx xxxx
    • 070 xxxx xxxx
    • 07624 xxxxxx
    • 076 xxxx xxxx
    • 07xxx xxxxxx
    • 08xx xxx xxxx
    • 09xx xxx xxxx

     

    Valid formats for geographic numbers include 2+8, 3+7, 4+6, 4+5, 5+5 and 5+4 (and 0+10 for NDO numbers).

    Non-geographic numbers mostly use 0+10 format, but some 0800 numbers and all 0500 numbers use 0+9 format.

    Most code found on the web caters for only a few of these, not the full set.

    The international format adds +44 and a space before the NSN digits.

    The national format adds the 0 trunk code before the NSN digits. For 01 and 02 numbers the area code should be in parentheses, except for NDO numbers (NDO numbers are those where subscriber number begins 0 or 1).

    NDO numbers are National Dialling Only. These have been around for several decades and need the area code to be dialled even when called locally from within the same area. These numbers are used for alarm systems, computer communication systems and other lines that are not dialled for voice calls. They are also used as the termination point for non-geographic numbers. NDO numbers are not supposed to be advertised nor directly called by subscribers. NDO numbers are always 0+10 format.

    There are proposals to open up the NDO ranges in some areas for use by normal subscribers starting some time in 2012.

    • Edited by lesset Monday, October 17, 2011 7:34 AM
    • Marked as answer by gadya Tuesday, October 18, 2011 2:59 PM
    Saturday, October 15, 2011 6:03 PM
    1. you might explain that NSN=National Significant Number and is just the whole phone number without the initial zero or +44.
    2. NDO numbers are new and experimental being trialled in just a couple of areas where they are running short of numbers. I'm not sure what NDO stands for but they force everyone in the area to dial the area code as well as the subscriber's number for all calls even if the area code is the same as that of the phone you are calling from. BT and Ofcom think this is less confusing than having two different area codes for the same town. I would disagree.

    Simon Jones
    • Marked as answer by gadya Tuesday, October 18, 2011 2:59 PM
    Saturday, October 15, 2011 11:02 PM
  • 1.  That text was already there, under the list.

      "The international format adds +44 and a space before the NSN digits."

      "The national format adds the 0 trunk code before the NSN digits."

    2. NDO numbers have been around for decades. I have now added some stuff about that in the answer above. There are now some proposals to use NDO numbers for normal subscribers. They have been used for other purposes for decades; and will continue to be used for those other purposes too.

    This is a useful page about NDO numbers: 

    http://www.aa-asterisk.org.uk/index.php/NDO

    • Edited by lesset Monday, October 17, 2011 7:35 AM
    • Marked as answer by gadya Tuesday, October 18, 2011 2:59 PM
    Sunday, October 16, 2011 6:43 AM
  • That other thread [ http://social.msdn.microsoft.com/Forums/en-US/lightswitchgeneral/thread/76498bca-30b7-4c68-9728-7069b93f2b6e - now closed ] lists these formats:

    (AAA) NNNNNNNN
    (AAAAA) NNNNNN
    +CC (AA) NNNNNNNN
    +CC (AAAA) NNNNNN

    Those are the national format and the international format for 2+8 and 4+6 format numbers. However, the placement of the 0 trunk code should be further clarified, and parentheses are NOT valid in the international format:

    (0AA)  NNNN NNNN
    (0AAAA)  NNNNNN
    +CC  AA  NNNN NNNN
    +CC  AAAA  NNNNNN

    The UK also uses 3+7, 4+5, 5+5 and 5+4 format for geographic numbers, as well as 0+10 for NDO numbers and 0+10 and 0+9 format for non-geographic numbers.

    There's a list of area codes using formats other than 2+8 and 4+6 here:

    http://www.aa-asterisk.org.uk/index.php/01_numbers


    • Edited by lesset Monday, October 17, 2011 7:31 AM
    • Marked as answer by gadya Tuesday, October 18, 2011 2:59 PM
    Sunday, October 16, 2011 6:53 AM