Time validation in text field

Hi All

 In an editable grid we used a text field as a time enter field . Currently we want to do validations as follow in the text field 9:02 AM in the editable how to achieve this scenario.

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    If you're prepared to force the user to use a fairly strict format, you could use RegEx to validate that the user enters text in the exact format of HH:MM AA.

    a!localVariables(
      local!24hourmatch: regexmatch(
        /* requires 2-digit hour from 00 thru 23 */
        pattern: "^(0[0-9]|1[0-9]|2[0-3]):[012345]\d$",
        searchString: ri!timeText
      ),
      
      local!12hourMatch: regexmatch(
        /* requires 1 or 2-digit hour from 1/01 to 12, plus AM or PM (case insensitive) */
        pattern: "^(0?[1-9]|1[012]):[012345]\d [AP]M$",
        searchString: ri!timeText
      ),
      
      or(
        local!12hourMatch,
        local!24hourmatch
      )
    )

Reply
  • 0
    Certified Lead Developer

    If you're prepared to force the user to use a fairly strict format, you could use RegEx to validate that the user enters text in the exact format of HH:MM AA.

    a!localVariables(
      local!24hourmatch: regexmatch(
        /* requires 2-digit hour from 00 thru 23 */
        pattern: "^(0[0-9]|1[0-9]|2[0-3]):[012345]\d$",
        searchString: ri!timeText
      ),
      
      local!12hourMatch: regexmatch(
        /* requires 1 or 2-digit hour from 1/01 to 12, plus AM or PM (case insensitive) */
        pattern: "^(0?[1-9]|1[012]):[012345]\d [AP]M$",
        searchString: ri!timeText
      ),
      
      or(
        local!12hourMatch,
        local!24hourmatch
      )
    )

Children
No Data