Skip to main content
October 9, 2023
Question

Validation for first letter case sensitive using regex match function

  • October 9, 2023
  • 7 replies
  • 1 view

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

)

7 replies

stefanhelzle0001
Brainy
October 9, 2023

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

October 9, 2023

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 

stefanhelzle0001
Brainy
October 9, 2023

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.