Restrict number of digits allowed for a field #inSalesforce

Restrict number of digits allowed for a field scenario:


If validation allows only 15 digit numbers to be entered into the field (Suppose CitizenNumber__c is a field in Account)


Validation Rule on Account:


OR( LEN(CitizenNumber__c) <> 15, NOT(REGEX(CitizenNumber__c,"^[0-9]+$")))


Error Message: Please enter 15 digits for the field. 


and 


If you want to allow blank values along with the above:


AND(NOT(ISBLANK(CitizenNumber__c)),

OR( LEN(CitizenNumber__c) <> 15, NOT(REGEX(CitizenNumber__c,"^[0-9]+$"))))


Error Message: Please enter 15 digits for the field. 

Comments