Validation for first letter case sensitive using regex match function

Certified Senior Developer

Hi 

Please be informed that i am trying to provide validation for a one user input field in a pattern like P (upper case).7 digits.2 digits.2 digits (if applicable) i have tried like below but for two conditions it was not working if first letter P is lower case also it was returning true and for last 2 digits if applicable then only it will be having those digits but it was expecting those two as mandatory. 

Could you please suggest on this

a!localVariables(

local!input:"P.8790889.87",

local!pattern:"[P].[0-9]{7}[.][0-9]{2}[.][0-9]{2}",

local!output: regexmatch(

local!pattern,local!input

),

local!output

)

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    I dropped your pattern description into ChatGPT:

    P\d{7}\.\d{2}\.\d{2}?

    Here's the breakdown of the modified pattern:

    P matches the uppercase letter "P" literally.
    \d{7} matches exactly 7 digits.
    \. matches a dot character.
    \d{2} matches exactly 2 digits.
    \. matches another dot character.
    \d{2} matches exactly 2 digits, and the ? at the end makes it optional (matches 0 or 1 occurrence).
    This pattern will match strings like "P1234567.12.34" (7 digits followed by a dot, followed by 2 digits, followed by a dot, followed by 2 digits), "P9876543.32.12" (7 digits followed by a dot, followed by 2 digits, followed by a dot, followed by 2 digits), and "P5678901.12" (7 digits followed by a dot, followed by 2 digits, but the last 2 digits are optional).

Reply
  • 0
    Certified Lead Developer

    I dropped your pattern description into ChatGPT:

    P\d{7}\.\d{2}\.\d{2}?

    Here's the breakdown of the modified pattern:

    P matches the uppercase letter "P" literally.
    \d{7} matches exactly 7 digits.
    \. matches a dot character.
    \d{2} matches exactly 2 digits.
    \. matches another dot character.
    \d{2} matches exactly 2 digits, and the ? at the end makes it optional (matches 0 or 1 occurrence).
    This pattern will match strings like "P1234567.12.34" (7 digits followed by a dot, followed by 2 digits, followed by a dot, followed by 2 digits), "P9876543.32.12" (7 digits followed by a dot, followed by 2 digits, followed by a dot, followed by 2 digits), and "P5678901.12" (7 digits followed by a dot, followed by 2 digits, but the last 2 digits are optional).

Children