1

I am trying to write a validation rule using REGEX that will enforce this format (1-10):(1-10) in a Text field.

Example: (2):(5)

Open parenthesis + # between 1 and 10 + Close parenthesis + colon + Open parenthesis + # between 1 and 10 + Close parenthesis

NOT(REGEX( Text_Field__c, needhelpwiththispart )
  • 1
    Have you tried anything, maybe, an online regex editor, such as this one? – battery.cord Apr 11 '17 at 19:13
  • I did batt...but I couldn't figure it out – Safari Steve Apr 11 '17 at 19:16
1

Try this regex:

[(]([1-9]|10)[)][:][(]([1-9]|10)[)]

In order, it matches:

[(] - Literal (

([1-9]|10) - 1 through 9, or 10

[)] - Literal )

[:] - Literal :

The rest is repeated from the above.

1

You should be able to do something like:

NOT(REGEX(Text_Field__c, "\\((10|[1-9])\\):\\((10|[1-9])\\)"))

Explanation

\((10|[1-9])\):\((10|[1-9])\)

  • \( matches the character ( literally (case sensitive)

  • 1st Capturing Group (10|[1-9])

    • 1st Alternative 10
      10 matches the characters 10 literally (case sensitive)
    • 2nd Alternative [1-9]
      Match a single character present in the list below [1-9]
      1-9 a single character in the range between 1 (ASCII 49) and 9 (ASCII 57) (case sensitive)
  • \) matches the character ) literally (case sensitive)
  • : matches the character : literally (case sensitive)
  • \( matches the character ( literally (case sensitive)
  • 2nd Capturing Group (10|[1-9])
    • 1st Alternative 10
      10 matches the characters 10 literally (case sensitive)
    • 2nd Alternative [1-9]
      Match a single character present in the list below [1-9]
      1-9 a single character in the range between 1 (ASCII 49) and 9 (ASCII 57) (case sensitive)
  • \) matches the character ) literally (case sensitive)
  • Thanks Adrian...that worked...what if I also want to allow 0 – Safari Steve Apr 11 '17 at 19:27
  • 1
    @SafariSteve Just change [1-9] to [0-9]. – Adrian Larson Apr 11 '17 at 19:29

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.