Answered by:
Format UK telephone number

Question
-
Hi All;
Does any one please help me to format all UK telephone number
Anyhelp much appreciated
Thanks
Pradnya07
Tuesday, February 11, 2014 10:42 AM
Answers
-
Hi,
For each of the formats you should use a distinct function, or you could combine all of them in a function (which could be hard in maintenance). Have a look at below piece of code:
/* Pass first arguement as the name of the field you want to validate. The second arguement is the pattern. Use symbols as they are. Instead of numbers use #. For example +21-83192720. Tha pattern should be +##-######## */ function PhoneNumberValidator() { var CurrentNumber = new String(Xrm.Page.getAttribute(arguments[0]).getValue()); var Pattern = new String(arguments[1]); if (CurrentNumber.length != 0 ) { if (Pattern.length != CurrentNumber.length) { alert('Format Error. The number must be ' + Pattern); Xrm.Page.getAttribute(arguments[0]).setValue(); return; } for (var i = 0; i < Pattern.length; i++) { if (Pattern.substr(i, 1) != '#' && CurrentNumber.substr(i, 1) != Pattern.substr(i, 1)) { alert('Format Error. The number must be ' + Pattern); Xrm.Page.getAttribute(arguments[0]).setValue(); return; } if (Pattern.substr(i, 1) == '#' && isNaN(Number(CurrentNumber.substr(i, 1)))) { alert('Format Error. The number must be ' + Pattern); Xrm.Page.getAttribute(arguments[0]).setValue(); return; } } } }
- Proposed as answer by Payman BiukaghazadehEditor Tuesday, February 11, 2014 12:55 PM
- Marked as answer by Payman BiukaghazadehEditor Saturday, March 1, 2014 1:45 PM
Tuesday, February 11, 2014 12:55 PMModerator -
Formatting requires validation. First you must validate that the number is a number that can be formatted. After that, you are going to have to make some kind of logic tree that goes through all the options for formatting a UK number. That isn't easy, and I don't think you're going to find a comprehensive solution just posted on the forum.
But validation is a strong first step, I would take the validation code posted above and start working from there.
The postings on this site are solely my own and do not represent or constitute Hitachi Solutions' positions, views, strategies or opinions.
- Proposed as answer by Payman BiukaghazadehEditor Tuesday, February 18, 2014 12:58 PM
- Marked as answer by Payman BiukaghazadehEditor Saturday, March 1, 2014 1:45 PM
Tuesday, February 11, 2014 1:40 PM
All replies
-
Hi there,
Go through the following link. use the javascript code on change of the field.
http://www.braemoor.co.uk/software/telnumbers.shtml
Thanks
If this post answers your question, please click "Mark As Answer" on the post and "Vote as Helpful" Thank you, DT
Tuesday, February 11, 2014 10:47 AM -
thanks for your reply
the code is to validate UK telephone i need to format UK telephone numbers
Pradnya07
Tuesday, February 11, 2014 10:50 AM -
check this link you get an idea
http://guruprasadcrm.blogspot.in/2011/11/phone-number-validation-using-java.html
ms crm
Tuesday, February 11, 2014 11:13 AM -
UK format is in 7 digit NSNs
9 digit NSNs
- (016977) 2xxx
- (016977) 3xxx
- (01xxx) xxxxx — click for detailed list
- 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 — click for detailed list
- 03xx xxx xxxx — click for detailed list
- 055 xxxx xxxx
- 056 xxxx xxxx
- 070 xxxx xxxx
- 07624 xxxxxx
- 076 xxxx xxxx
- 07xxx xxxxxx
- 08xx xxx xxxx — click for detailed list
- 09xx xxx xxxx
I need to code format for all of this
Pradnya07
Tuesday, February 11, 2014 11:49 AM -
Hi,
For each of the formats you should use a distinct function, or you could combine all of them in a function (which could be hard in maintenance). Have a look at below piece of code:
/* Pass first arguement as the name of the field you want to validate. The second arguement is the pattern. Use symbols as they are. Instead of numbers use #. For example +21-83192720. Tha pattern should be +##-######## */ function PhoneNumberValidator() { var CurrentNumber = new String(Xrm.Page.getAttribute(arguments[0]).getValue()); var Pattern = new String(arguments[1]); if (CurrentNumber.length != 0 ) { if (Pattern.length != CurrentNumber.length) { alert('Format Error. The number must be ' + Pattern); Xrm.Page.getAttribute(arguments[0]).setValue(); return; } for (var i = 0; i < Pattern.length; i++) { if (Pattern.substr(i, 1) != '#' && CurrentNumber.substr(i, 1) != Pattern.substr(i, 1)) { alert('Format Error. The number must be ' + Pattern); Xrm.Page.getAttribute(arguments[0]).setValue(); return; } if (Pattern.substr(i, 1) == '#' && isNaN(Number(CurrentNumber.substr(i, 1)))) { alert('Format Error. The number must be ' + Pattern); Xrm.Page.getAttribute(arguments[0]).setValue(); return; } } } }
- Proposed as answer by Payman BiukaghazadehEditor Tuesday, February 11, 2014 12:55 PM
- Marked as answer by Payman BiukaghazadehEditor Saturday, March 1, 2014 1:45 PM
Tuesday, February 11, 2014 12:55 PMModerator -
Hi Thanks for yur reply
i need a code to format not validate
Pradnya07
- Proposed as answer by Payman BiukaghazadehEditor Tuesday, February 18, 2014 12:58 PM
Tuesday, February 11, 2014 12:58 PM -
Formatting requires validation. First you must validate that the number is a number that can be formatted. After that, you are going to have to make some kind of logic tree that goes through all the options for formatting a UK number. That isn't easy, and I don't think you're going to find a comprehensive solution just posted on the forum.
But validation is a strong first step, I would take the validation code posted above and start working from there.
The postings on this site are solely my own and do not represent or constitute Hitachi Solutions' positions, views, strategies or opinions.
- Proposed as answer by Payman BiukaghazadehEditor Tuesday, February 18, 2014 12:58 PM
- Marked as answer by Payman BiukaghazadehEditor Saturday, March 1, 2014 1:45 PM
Tuesday, February 11, 2014 1:40 PM