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).

  • 0
    Certified Senior Developer
    in reply to Stefan Helzle

    Thank you so much for your suggestion Stefan 

    But when i tried the above provided pattern even if i am giving the input in correct pattern it was returning as false only kindly find the below snippet for the same 

  • 0
    Certified Lead Developer
    in reply to dharanik2600

    Could it be that you need to make the last dot optional? Or better the last group of a dot plus the two digits.

    I suggest to use a regex tool to develop and verify your pattern.

  • The string you're testing here doesn't match your regex.  Your regex is looking for "P" followed immediately by 7 digits and THEN a "." character.

    But that's not what you're inputting.

    If we fix these, it starts working:

    (or)

    Additionally if you want the last "period two digits" grouping to be purely optional (zero or one times), you'll need to apply the "?" operator to the group of things you need to be considered optional, including the extra "." character:

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Thank so much for your suggestions Mike it working fine now with your suggestions but if we are giving lower case p it was returning true only it has to be case sensitive means only Upper case P it should accept could you please suggest on this

  • 0
    Certified Lead Developer
    in reply to dharanik2600

    I suggest to read the documentation. The regexmatch function has some optional flags:

    regexFlags (Text): (Optional, Defaults to "is" to match original functionality) String of the regex flags you wish to apply, for example "gms". Available options are 'g' find all matches, 'i' case insensitive search, 'm' multiline search, 's' treats the entire string as a single line, 'u' unicode-aware case folding, 'x' ignores comments starting with hashtags and whitespaces in the pattern, 'd' enables unix line mode.

Reply
  • 0
    Certified Lead Developer
    in reply to dharanik2600

    I suggest to read the documentation. The regexmatch function has some optional flags:

    regexFlags (Text): (Optional, Defaults to "is" to match original functionality) String of the regex flags you wish to apply, for example "gms". Available options are 'g' find all matches, 'i' case insensitive search, 'm' multiline search, 's' treats the entire string as a single line, 'u' unicode-aware case folding, 'x' ignores comments starting with hashtags and whitespaces in the pattern, 'd' enables unix line mode.

Children