6

When I add Phone field in custom Object, I want to the user to enter minimum of 10 digits, if the user enters less than 10 digits they should get error [Just the numbers, no need of any special characters inclusion like +1 (666) 777-8910 just '6667778910']. Can anyone please help me with the formula for this criteria to enter in validation rule?

Thanks in advance!

3

As @crmprogdev mentioned, I would recommend to use RegEx. See this example for US Phone number has 10 digits in (999) 999-9999 format: NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}")) in UsefulValidationRules

If you don't like RegEx, you can use an alternativly an onion-like SUBSTITUTE. If you need other characters excluded, you'll have to add more SUBSTITUTEs. TRIM removes white space and LEN counts the cleaned results:

 LEN(
   SUBSTITUTE(
     SUBSTITUTE(
       SUBSTITUTE( 
         TRIM(YourFieled__c) 
       , "+", "")
     , "(", "")
   , ")", "")
 ) < 10

See also

| improve this answer | |
  • 1
    Actually, you can use RegEx to replace characters. See this example for US Phone number has 10 digits in (999) 999-9999 format: NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}")) in UsefulValidationRules. This could be modified to handle other situations as well. – crmprogdev Mar 7 '15 at 15:27
  • @crmprogdev - thanks for your headsup, you are right. I updated my answer. – Uwe Heim Mar 7 '15 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.