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
Sfdc11Sfdc11 

REGEX

Hi ,

I need to have Regex to accpet either of format 

(45)3456-3456 (or)

+4564564523434 ->size can be more than 10 digit but with + sign

 

Please Help out..

GlynAGlynA

Here's the regular expression you need:

 

String regex = '\\(\\d{2}\\)\\d{4}\\-\\d{4}|\\+\\d+';

system.debug( Pattern.matches( regex, '(42)1234-1234' ) );
system.debug( Pattern.matches( regex, '+12345678901234' ) );
system.debug( Pattern.matches( regex, '(42)1234 1234' ) );

The first two debugs print 'true' and the third one prints 'false'.

 

If this helps, please mark it as a solution, and give kudos (click on the star) if you think I deserve them. Thanks!

 

-Glyn Anderson
Certified Salesforce Developer | Certified Salesforce Administrator