function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
jojoforcejojoforce 

REGEX - Validation Rule

I'm trying to create a validation rule that will restrict the users from entering more than 20 characters or non-numeric characters..

 

Validation Error message: Please enter a numbers only and should not be more than 20 characters.

 

Below is a sample formula in my validation rule, however I couldn't seem to get it working correctly. Please help. Thanks

 

OR(
	LEN(input__c)>20,
	REGEX(input__c,"\\D*")
)

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
BA_AdminBA_Admin

Try this

 

OR (LEN(input__c)>20,

       NOT(ISNUMBER(input__c))

      )

All Answers

BA_AdminBA_Admin

It should work , when you say it's not working are you able to save it even if the length is greater then 20 characters ?

jojoforcejojoforce

The 20 character limitation is working.. however, I can still enter non-numeric.. For example, "12343ABC" it should not accept it because of the "ABC"

 

These are sample valid inputs:

122345

123423423

12345678901234567890

 

These are NOT valid inputs:

1232A

12F34

1234567890123456789011

BA_AdminBA_Admin

Try this

 

OR (LEN(input__c)>20,

       NOT(ISNUMBER(input__c))

      )

This was selected as the best answer
BA_AdminBA_Admin

Did it worked?

jojoforcejojoforce

Yup it did. Awesome! Thanks man!