format.UkTelNumber ( )

Function stats

Average user rating
5.0000
102
214
9999
Support
FileMaker 7.0 +
Date posted
03 April 2009
Version
1
Recursive function
No

Author Info
 TimA

5 functions

Average Rating 5.0

author_avatar



 

Function overview

Prototype

format.UkTelNumber  ( telNo )


Parameters

telNo  


Description

Tags:  telephone   phone   Format  

Formats a string on numbers/letters to UK telephone number format

Examples

Sample input

format.UkTelNumber("01234567890x123")


Sample output

01234 567890 x123

 

Function code

/*

Name:
format.UkTelNumber

History:
Created by Tim Anderson, Tim Anderson Group
www.timanderson.co.uk
Creation Date: 3 April 2009


Purpose:
A function to format numbers into my preferred uk format. Could easily be tweaked to add brackets or any text.

Parameters:
telNo


Example:
format.UkTelNumber("01234567890")
returns 01234 567890
format.UkTelNumber("01234567890x123")
returns 01234 567890 x123

Requires Other Custom Functions:
None

Other Notes:
If you are inputting numbers directly use quotes, otherwise the initial 0 will be dropped. When referencing fields make sure they are defined as text.
Definition of _partA can be tweaked as new number formats are released/discovered

Options:
None


*/

Let([
//------------------------- VARIABLES
_number=Substitute(telNo;" ";"");
_second=Middle ( _number ; 2 ; 1 );
_fourth=Middle ( _number ; 4 ; 1 );
_length=Length(_number);
_partA=Case(_second=7;5;_second="1" and _fourth="1";4;_second="8";4;_second="2";3;_second="3";3;5);
_partB=Case(_partA = "3" or _partA="4";3;Min(_length-_partA;6));
_partC= 11-_partA-_PartB;
_extension=_length-11

];
//------------------------- RESULT

Left(_number;_partA) & " " &Middle ( _number;_partA+1; _partB) & " " & Middle ( _number;_partA+_partB+1;_partC)& " " & Middle ( _number;_partA+_partB+_partC+1; _extension)

) // End Let



// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/214

    Prototype: format.UkTelNumber( telNo )
    Function Author: TimA (http://www.fmfunctions.com/mid/102)
    Last updated: 03 April 2009
    Version: 1

*/
// ===================================

 

Comments

Zerocool
11 December 2009



I may need a little help implementing this on my field. It works when i set my field as a type:calculation, but then you cant edit the content. So i tried setting the field as type:text and validated by calculation but it does perform the function.
Any ideas??? Thanks
  General comment

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (28)
XML  (26)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Layout  (15)
Interface  (15)
Text  (14)
Variables  (12)
Filter  (11)
Layout Objects  (11)
Design  (10)
Array  (8)