2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
4 * This component and the accompanying materials are made available
5 * under the terms of "Eclipse Public License v1.0"
6 * which accompanies this distribution, and is available
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
20 #ifndef __TULPHONENUMBERUTILS_H__
21 #define __TULPHONENUMBERUTILS_H__
27 Class offers static methods for parsing and validating phone numbers.
28 Phone Parser API provides methods which are used to parse and validate
29 phone numbers. The API consists of the TulPhoneNumberUtils class.
31 Examples of valid phone numbers:
35 Even though both of the above examples are valid phone numbers, only 1) is
36 accepted as a phone number by many systems. To convert 2) to 1), use the
37 parsing method of the API.
42 #include <tulphonenumberutils.h>
44 // Example shows how to use the parsing method of the API.
46 // A number to be parsed.
47 TBuf<50> number1 = _L("+358 (40) 123 132");
49 // Type of the phone number to be parsed is a regular phone number.
51 TulPhoneNumberUtils::NormalizePhoneNumber( number1,
52 TulPhoneNumberUtils::EPlainPhoneNumber );
54 // The phone number number1 is a valid regular phone number.
55 // After parsing validNumber1 is ETrue and
56 // number1 is "+35840123132".
57 // Do something like SendSMS( number1 ) etc.
59 // A number to be parsed.
60 TBuf<50> number2 = _L("+358 (40) 123p132"); // note 'p'
62 // Type of the phone number to be parsed is a regular phone number.
64 TulPhoneNumberUtils::NormalizePhoneNumber( number2,
65 TulPhoneNumberUtils::EPlainPhoneNumber );
67 // The phone number number2 is not a valid regular phone number.
68 // After parsing validNumber2 is EFalse and
69 // number2 is "+358 (40) 123p132" (unchanged).
75 NONSHARABLE_CLASS(TulPhoneNumberUtils)
79 * Enumeration for phone number types.
80 * Used to specify the type of phone numbers in methods of
81 * TulPhoneNumberUtils class.
85 /** The supplied phone number is a regular phone number. */
87 /** The supplied phone number is a contact card number. */
89 /** The supplied phone number is is a phone client number. */
91 /** The supplied phone number is an SMS number. */
95 IMPORT_C static TBool Normalize( TDes& aNumber, TPhoneNumberType aType = EPlainPhoneNumber);
96 IMPORT_C static TBool IsValid( const TDesC& aNumber, TPhoneNumberType aType = EPlainPhoneNumber );
98 inline static TBool ParsePhoneNumber( TDes& aNumber, TInt aType );
99 inline static TBool IsValidPhoneNumber( const TDesC& aNumber, TInt aType );
101 static TBool IsValidPhoneNumber( const TDesC& aNumber, const TDesC& aValidChars);
102 static void ParseInvalidChars( TDes& aNumber, const TDesC& aInvalidChars);
105 // For source compatibility with S60
108 inline TBool TulPhoneNumberUtils::ParsePhoneNumber( TDes& aNumber, TInt aType )
109 { return TulPhoneNumberUtils::Normalize(aNumber, static_cast<TPhoneNumberType>(aType)); }
111 inline TBool TulPhoneNumberUtils::IsValidPhoneNumber( const TDesC& aNumber, TInt aType )
112 { return TulPhoneNumberUtils::IsValid(aNumber, static_cast<TPhoneNumberType>(aType)); }
114 #endif // __TULPHONENUMBERUTILS_H__