I have a custom field on an object which should allow values based on the following JavaScript REGEX.


Can anyone help me how to use this REGEX in validation rule ?


You should screen with \ such literals as \, ', " and use REGEX(text, regex_text) in validation rule's formula field.

So, for example, if you want your field match the regex, you should write the formula like this:

NOT(REGEX(CustomField__c, "[\\sa-zA-Z0-9.,:?;%/()\'!\"\"-]*"))

Explanation: add NOT(), therefore if the field matches regex it does not be caught as error condition.

Here is the link to documentation: https://help.salesforce.com/articleView?id=customize_functions_i_z.htm&type=5

  • I tried this. but now its not even allowing me to save when the value is just alphabets – Junaid P Khader Jul 18 '19 at 7:58
  • 1
    [\\sa-zA-Z0-9.,:?;%/()\'!\"\"-]* – Mariia Illarionova Jul 18 '19 at 9: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.