2 * Copyright (c) 2002-2006 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
14 * Description: Offers methods for parsing and validating phone numbers.
19 #ifndef COMMONPHONEPARSER_H
20 #define COMMONPHONEPARSER_H
29 * Class offers static methods for parsing and validating phone numbers.
30 * Phone Parser API provides methods which are used to parse and validate
31 * phone numbers. The API consist of the CommonPhoneParser class.
33 * Examples of valid phone numbers:
35 * 2. +358 (50) 123 4567
37 * Even though both of the above examples are valid phone numbers, only 1) is
38 * accepted as a phone number by many systems. To convert 2) to 1), use the
39 * parsing method of the API.
45 * #include <commonphoneparser.h>
47 * // Example shows how to use the parsing method of the API.
49 * // A number to be parsed.
50 * TBuf<50> number1 = _L("+358 (40) 123 132");
52 * // Type of the phone number to be parsed is a regular phone number.
53 * TBool validNumber1 =
54 * CommonPhoneParser::ParsePhoneNumber( number1,
55 * CommonPhoneParser::EPlainPhoneNumber );
57 * // The phone number number1 is a valid regular phone number.
58 * // After parsing validNumber1 is ETrue and
59 * // number1 is "+35840123132".
60 * // Do something like SendSMS( number1 ) etc.
62 * // A number to be parsed.
63 * TBuf<50> number2 = _L("+358 (40) 123p132"); // note 'p'
65 * // Type of the phone number to be parsed is a regular phone number.
66 * TBool validNumber2 =
67 * CommonPhoneParser::ParsePhoneNumber( number2,
68 * CommonPhoneParser::EPlainPhoneNumber );
70 * // The phone number number2 is not a valid regular phone number.
71 * // After parsing validNumber2 is EFalse and
72 * // number2 is "+358 (40) 123p132" (unchanged).
75 * @lib commonengine.lib
79 class CommonPhoneParser
84 * Enumeration for phone number types.
85 * Used to specify the type of phone numbers in methods of
86 * CommonPhoneParser class.
90 /** The associated phone number is a regular phone number.
93 /** The associated phone number is a contact card number.
96 /** The associated phone number is is a phone client number.
99 /** The associated phone number is an SMS number.
105 * Parses the supplied phone number. This method removes irrelevant
106 * characters and white spaces from the supplied phone number. Allowed
107 * characters are determined by phone number type.
109 * @param aNumber will be checked and parsed. After returning contains
110 * the parsed number if the supplied phone number was a valid phone
111 * number. If the number was not valid no parsing will be done.
112 * @param aType is the type of the supplied phone number.
113 * @return ETrue if the supplied phone number is a valid number of the
114 * supplied type and the parsing succeeds. Otherwise EFalse.
116 IMPORT_C static TBool ParsePhoneNumber( TDes& aNumber,
117 TPhoneNumberType aType );
120 * Checks if string is a valid phone number.
121 * This method checks if the supplied phone number is a valid phone
122 * number of the supplied type.
124 * @param aNumber which validity will be checked.
125 * @param aType is the type of the supplied phone number.
126 * @return ETrue if the supplied phone number is a valid number of the
127 * supplied type. Otherwise EFalse.
129 IMPORT_C static TBool IsValidPhoneNumber( const TDesC& aNumber,
130 TPhoneNumberType aType );
133 * This method is meant for internal use of Phone Parser.
134 * Check if string is a valid phone number
136 * @param aNumber Number which will be checked
137 * @param aValidChars Characters that are valid for the number.
138 * Note! Some chars have special rules. See Find Item
139 * UI specification for more info.
141 * @return ETrue if the number was valid, otherwise EFalse.
143 static TBool IsValidPhoneNumber( const TDesC& aNumber,
144 const TDesC& aValidChars);
146 * This method is meant for internal use of Phone Parser.
147 * Parses invalid characters from a string
149 * @param aNumber Number which will be parsed.
150 * @param aInvalidChars Characters that are invalid.
152 static void ParseInvalidChars( TDes& aNumber,
153 const TDesC& aInvalidChars);
156 #endif // COMMONPHONEPARSER_H