Hi We all know USA phone number "(999) 999-9999" . How do we restrict user from invalid entry ? We can create validation rule. Error Condition Formula:- NOT(REGEX(Phone__c, "^\\(\\d{3}\\)\\s?\\d{3}-\\d{4}")) Error Message:- US phone numbers should be in this format: (999) 999-9999. if you want to add validation in controller, below is the method public static boolean isValid(String phone){ String PhoneRegex = ' ^\\(\\d{3}\\)\\s?\\d{3}-\\d{4} '; Pattern MyPattern = Pattern.compile(PhoneRegex); // then instantiate a new Matcher object “MyMatcher” Matcher MyMatcher = MyPattern.matcher(phone); if (!MyMatcher.matches()) { return false; ...
A place where you have to land for exploring Salesforce