function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
The new LearnerThe new Learner 

how to exclude alaphbets in number

Hi Experts,

There is an email is comes from webservice, in that email we are searching for the policy number with that policy number we are creating case but problem here is that its  reading phone number also and creating case, so i observerd that phone number is coming prefix as "tel,T,telephone,phone,fax,F,+27" if i find anythig like this i need to ignore.
below is the expression we are using. can anyone help me please

public static final String REGEX_PATTERN_POLICY_NUMBER = '[0-9]{6,12}';
VinayVinay (Salesforce Developers) 
Hi,

Try to check below links which can help you on your Regex functionality in Apex 

http://www.infallibletechie.com/2015/09/mobile-number-validation-using-apex-in.html
https://www.greytrix.com/blogs/salesforce/2015/05/27/use-of-regular-expression-in-apex/

Hope above information was helpful.

Please mark as Best Answer so that it can help others in the future.

Thanks,
Vinay Kumar
The new LearnerThe new Learner
HI Vinay ,

 have requirment where it has to read an email subject if it contains a policy number it has to create case but problem is that it sometimes its considering the mobile number also. to avoid this i am written below class please help me whether its correct or not.
Regular expression:

public static final String REGEX_PATTERN_EXACT_NUMBER = '^[A-Za-z]{0,4}[0-9]{6,10}';
Pattern regexPattern = Pattern.compile(REGEX_PATTERN_POLICY_NUMBER);

I am calling below method like this .

policyNumbersMap = Case.populatePolicyNumberMap(
                            policyNumbersMap,
                            regexPattern.matcher(policyCase.Subject),
                            policyCase
                    );


public static Map<Id, Set<String>> populatePolicyNumberMap(Map<Id, Set<String>> policyNumbersMap, Matcher match, Case aCase)
    {
        Pattern regexExactPattern = Pattern.compile(REGEX_PATTERN_EXACT_NUMBER);
		String[] emailAddressList = new String[]{'tel', 'telephone', 'phone', 'fax', 'F','+27','T'};
		  
        if (policyNumbersMap == null)
        {
            policyNumbersMap = new Map<Id, Set<String>>();
        }
		for (String emailAddress : emailAddressList) 
		{
          System.debug('Email address: ' + emailAddress);
          Matcher m = regexExactPattern.matcher(emailAddress);
          if (m.matches()) 
		  {
		    null;
		  }
			else
			{
			Set<String> values = policyNumbersMap.get(aCase.Id);
                    if (values == null)
                    {
                        values = new Set<String>();
                    }
                    values.add(exactMatch.group());
                    policyNumbersMap.put(aCase.Id, values);
			}
		    
          }
		  return policyNumbersMap;
       
         }