Thursday, June 9th, 2011

Telephone number formatting – validation

In a recent project the instruction was to validate a telephone input field. Simple enough you might think in peoplecode?

The answer is actually yes, but searching for a reference code I quickly discovered this has not been done a lot in peoplecode. So I decide to share a solution code snippets in contrast to Javascript en Java validation of which I have a relative experience.

 

The code snippet in the image uses a regex (Regular Expressions) used in both Javascript en Java to do sophisticated pattern matching, which can often be helpful in form validation. Which can be used to check whether a phone number or an email address entered into a form field is syntactically correct.

Code: http://blog.stevenlevithan.com/archives/validate-phone-number

 

 

 

 

 

 

 

 

 

The regex imports the regex Java class and uses it in the same way as Javascript.

Code: http://www.mkyong.com/java/how-do-validate-phone-number-in-java-regular-expression/

 

 

To replicate the above Javascript and Java phone validation code in peoplecode, the checks below was built into the phone field of the Component.

Note: The format below took account of not so standard numbers like 09000-000 etc. So it still depends on you to determine the required format and adjust the code accordingly.

 

 

 Viewed 6229 times by 3009 visitors


Category: General / Technical
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

One Response

June 9, 2011
Chiron
avatar

Validation against ITU-T E.123 “Notation for national and international telephone numbers, e-mail addresses and Web addresses” http://www.itu.int/rec/T-REC-E.123-200102-I/en might be more useful. Eg, for international numbers, spaces can be used anywhere (eg for French style pair grouping +33 1 23 45). And parenthesis and hyphen are not valid in international numbers.

Also ITU-T E.164 “The international public telecommunication numbering plan” http://www.itu.int/rec/T-REC-E.164-201011-I/en gives a maximum number length of 15 digits (ie not including the + or any spaces).

[Reply to this comment]