I am pretty new to Validation rules, this validation throws an error even if the field is 10 digits long. I have to bound users to populate the field no more than 10 digits

NOT(REGEX(USI_Number__c, "(\\d){10}"))
  • What should happen if they enter less than 10 characters? – Boris Bachovski Jan 12 '15 at 2:41
  • it should give a validation error – Jovi Jan 12 '15 at 3:45

There is the LEN function which returns number of characters in a string, so your validation should be something like:

NOT(ISBLANK(USI_Number__c)) && (LEN(USI_Number__c) >= 10 || NOT(REGEX(USI_Number__c, "(\\d)")
  • This is not letting me save the field even if the numbers are 10 – Jovi Jan 12 '15 at 4:06
  • My apologies, use >=10 instead of >10 – Boris Bachovski Jan 12 '15 at 4:09
  • No its not working still its still giving an error – Jovi Jan 12 '15 at 4:16

AND( !ISBLANK(USI_Number__c), LEN(USI_Number__c)<>10)

This works


Validation rule always checks for error condition to be true. So if the formula you have written in the validation rule is evaluating to true it will throw error.


I tried following validation rule:

NOT(ISBLANK(temp_number__c )),
NOT(REGEX(temp_number__c , "(\\d){10}"))

I tried this and it works absolutely fine for your conditions. Only one addition to it. You must have created a Text field 'USI_Number__c' , enter its length as 10.

Hope this solves your problem. :)

  • No i have to restrcit users if they populate the field they should always put 10 digits – Jovi Jan 12 '15 at 5:19
  • @Jovi yes that's what the formula above does......did you try that? – Yogesh D Jan 12 '15 at 5:24
  • Yes its still giving an error AND( !ISBLANK(USI_Number__c), LEN(USI_Number__c)<>10) – Jovi Jan 12 '15 at 5:37
  • @Jovi have updated my solution...please check!!! – Yogesh D Jan 12 '15 at 5:40

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.