0

There is a validation rule that I don´t fully understand. Can anyone please help me to understand the meaning of this REGEX?

NOT(REGEX( BillingCity , "^[\\p{Ll}\\p{Lu}\\p{Lt}\\p{Lo}\\p{Nd}\\p{Pc}\\p{Pi}\\p{Pf} .\\(\\)\\-\\+&@!'?/]+$"))
1

I find the Explanation section on regex101 very useful. You'll have to unescape your backslashes (replace (\\ with \), and I think you are missing an escape on your final forward slash, so here's what I fed into their parser:

^[\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Pc}\p{Pi}\p{Pf} .\(\)\-\+&@!'?\/]+$

And here's their explanation:

  • ^ asserts position at start of the string

  • Match a single character present in the list below
    [\p{Ll}\p{Lu}\p{Lt}\p{Lo}\p{Nd}\p{Pc}\p{Pi}\p{Pf} .\(\)\-\+&@!'?\/]+

    • + Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
    • \p{Ll} matches a lowercase letter that has an uppercase variant
    • \p{Lu} matches an uppercase letter that has a lowercase variant
    • \p{Lt} matches a letter that appears at the start of a word when only the first letter of the word is capitalized
    • \p{Lo} matches a letter or ideograph that does not have lowercase and uppercase variants
    • \p{Nd} matches a digit zero through nine in any script except ideographic scripts
    • \p{Pc} matches a punctuation character such as an underscore that connects words
    • \p{Pi} matches any kind of opening quote
    • \p{Pf} matches any kind of closing quote
    • . matches a single character in the list . (case sensitive)
    • \( matches the character ( literally (case sensitive)
    • \) matches the character ) literally (case sensitive)
    • \- matches the character - literally (case sensitive)
    • \+ matches the character + literally (case sensitive)
    • &@!'? matches a single character in the list &@!'? (case sensitive)
    • \/ matches the character / literally (case sensitive)
  • $ asserts position at the end of the string, or before the line terminator right at the end of the string (if any)

The ^[...]+$ formulation basically means you have a string entirely made up of whitelisted characters (everything replaced by ...) in any order. Note that this does not mean your string must contain any particular character in the whitelist (for example, it doesn't have to contain & to be valid, nor a lowercase letter that has an uppercase variant).

0

This might help you in some way ---

  • \p{Ll} or \p{Lowercase_Letter}: a lowercase letter that has an uppercase variant.
  • \p{Lu} or \p{Uppercase_Letter}: an uppercase letter that has a lowercase variant.

  • \p{Lt} or \p{Titlecase_Letter}: a letter that appears at the start of a word when only the first letter of the word is capitalized.

  • \p{Lo} or \p{Other_Letter}: a letter or ideograph that does not have lowercase and uppercase variants.

  • \p{Nd} or \p{Decimal_Digit_Number}: a digit zero through nine in any script except ideographic scripts.

  • \p{Pc} or \p{Connector_Punctuation}: a punctuation character such as an underscore that connects words.

  • \p{Pi} or \p{Initial_Punctuation}: any kind of opening quote.

    • \p{Pf} or \p{Final_Punctuation}: any kind of closing quote.

For more Search "Unicode Categories in REGEX"

  • Hi Nilesh, thx for that, do i get that right, that its state, when the city starts with a big Letter followed by small letters, this is accepted? But why would you put that in a field validation for City? What about the rest of the code, after the Pf? – Ralf Wittenberger Nov 17 '15 at 11:00

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.