I am trying to create a validation rule for US format number and using the following regex Validation

NOT(REGEX(Phone, "\\D*?(\\d\\D*?){10}"))

The above seems like a standard regex which will only allow saving for (000) 000-0000 format number.

However, if I enter characters in the following format (000) 000-0000yyy. It is still allowing save.

  • do you want your number only of 10 digits? – sanket kumar Aug 31 '18 at 8:28
  • I can add a length check to restrict it to 10 digits. What I want to understand is that why the regex is accepting the extra string characters, when Salesforce documentation is saying that the regex just allows number in US format which should actually be the format (000) 000-0000 – user55791 Aug 31 '18 at 8:31

You can try the below one as this could make sure that the phone contains only numbers.

NOT( OR( ISBLANK(Phone), REGEX( Phone,"(\\D?[0-9]{3}\\D?)[\\s][0-9]{3}-[0-9]{4}")))

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.