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 )
2
  • 1
    Have you tried anything, maybe, an online regex editor, such as this one? Apr 11, 2017 at 19:13
  • I did batt...but I couldn't figure it out Apr 11, 2017 at 19:16

2 Answers 2

2

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)
2
  • Thanks Adrian...that worked...what if I also want to allow 0 Apr 11, 2017 at 19:27
  • 1
    @SafariSteve Just change [1-9] to [0-9].
    – Adrian Larson
    Apr 11, 2017 at 19:29
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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .