voipplugins/svtlogging/src/svtphonenumbervalidator.cpp
branchRCL_3
changeset 22 d38647835c2e
parent 0 a4daefaec16c
equal deleted inserted replaced
21:f742655b05bf 22:d38647835c2e
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     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".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "svtphonenumbervalidator.h"
       
    20 
       
    21 // ======== MEMBER FUNCTIONS ========
       
    22 
       
    23 // ---------------------------------------------------------------------------
       
    24 // SvtPhoneNumberValidator::IsValidNumber
       
    25 // ---------------------------------------------------------------------------
       
    26 //
       
    27 TBool SvtPhoneNumberValidator::IsValidNumber( const TDesC& aCandidate )
       
    28     {
       
    29     if ( aCandidate.Length() != 0 
       
    30             && AreStartCharactersValid( aCandidate )
       
    31             && ContainsValidCharacters( aCandidate ) )
       
    32         {
       
    33         return ETrue;
       
    34         }
       
    35     else
       
    36         {
       
    37         return EFalse;
       
    38         }
       
    39     }
       
    40 
       
    41 
       
    42 // ---------------------------------------------------------------------------
       
    43 // SvtPhoneNumberValidator::ContainsValidCharacters
       
    44 // ---------------------------------------------------------------------------
       
    45 //
       
    46 TBool SvtPhoneNumberValidator::ContainsValidCharacters( 
       
    47         const TDesC& aCandidate )
       
    48     {
       
    49     _LIT( KAllowedCharsInPhoneNumber, "0123456789*+pw#PW" );
       
    50     
       
    51     TLex input( aCandidate );
       
    52     TPtrC validChars( KAllowedCharsInPhoneNumber );
       
    53     while ( validChars.Locate( input.Peek() ) != KErrNotFound )
       
    54         {
       
    55         input.Inc();
       
    56         }
       
    57     
       
    58     return ( !input.Remainder().Length() );
       
    59     }
       
    60 
       
    61 
       
    62 // ---------------------------------------------------------------------------
       
    63 // SvtPhoneNumberValidator::AreStartCharactersValid
       
    64 // ---------------------------------------------------------------------------
       
    65 //
       
    66 TBool SvtPhoneNumberValidator::AreStartCharactersValid( 
       
    67         const TDesC& aCandidate )
       
    68     {
       
    69     TBool isValidStart( ETrue );
       
    70     
       
    71     TChar firstChar  = '0';
       
    72     TChar secondChar = '0';
       
    73     TInt candidateLength( aCandidate.Length() );
       
    74     if ( 0 < candidateLength )
       
    75         {
       
    76         firstChar = aCandidate[0];
       
    77         firstChar.LowerCase();
       
    78         }
       
    79     
       
    80     if ( 1 < candidateLength )
       
    81         {
       
    82         secondChar = aCandidate[1];
       
    83         secondChar.LowerCase();
       
    84         }
       
    85     
       
    86     if ( firstChar == 'p' || firstChar == 'w' )
       
    87         {
       
    88         isValidStart = EFalse;
       
    89         }
       
    90     
       
    91     if ( ( firstChar == '+' && secondChar == '+' ) ||
       
    92          ( firstChar == '+' && secondChar == 'p' ) ||
       
    93          ( firstChar == '+' && secondChar == 'w' ) )
       
    94         {
       
    95         isValidStart = EFalse;
       
    96         }
       
    97     
       
    98     return isValidStart;
       
    99     }