0

I have a custom field called GMPI__c and I need to create a validation rule with the following requirements.

  1. User can enter numbers 0-9 only.
  2. The field is NOT required, so it can be left blank
  3. No special characters, decimals, commas, or negative numbers.
  4. Number must also be unique
  5. Data type can be either number or text

I created the field with a text data type and number data type and I'm running into problems with both. Can someone help me figure this out?

Here is the Text data type. It meets all requirements except the decimals are still present in the number.

NOT(
   OR(
      ISBLANK(GMPI__c),
      VALUE(GMPI__c) > 0,
      REGEX(TEXT(VALUE(GMPI__c)), "^[+]?\\d+$")
      )
)

Here is the Number data type. It meets all requirements except the commas are still showing up in the number.

NOT(
    OR( 
        REGEX(TEXT(GMPI__c), "^[+]?\\d+$"),  
        GMPI__c > 0,
        ISBLANK(GMPI__c)
        )
)
0

Please let me know is this stack over flow question answer your question?

https://stackoverflow.com/questions/57991064/salesforce-validation-rule-regex

Thanks.

1
  • I replaced my formula in the Number datatype field with the code on the link you provided and the commas are still showing up. So I edited the Text data type field with the formula and it is meeting all requirements. Thanks MohanRaj Sep 25 at 13:48

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.