Skip to main content
New Participant
Apr 1, 2022 4:19 AM UTC
Question

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.

    9 replies

    gopalk2865
    Participating Frequently
    Apr 1, 2022 5:18 AM UTC

    hi nizara0003, Its difficult to understand your requirement , could you please explain little bit more about your use case?

    New Participant
    Apr 1, 2022 5:22 AM UTC

    Hi 

     In editable grid we need to have time field in appian we don't have time field in editable grid. So to have time field i used  text field. Now the problem is its accepting all the values. Here i need to check the text field has to accept only time else need to throe some validation message.

    gopalk2865
    Participating Frequently
    Apr 1, 2022 5:25 AM UTC

    Ok. May i know why are you using text field ? is there any restriction on using date field?

    harshitb6843
    Brainy
    Apr 1, 2022 6:51 AM UTC

    Hi there,

    You can use validation in the below manner. 

    Split the text on semicolon(:) and check there should be 2 values. 
    On the first value, the integer value should be greater than equal to 0 and lesser than 25.
    On the second value, split it again on space( ) and check there should be again 2 values. 
    The first value should be again in the specific range.  The second value should be one of them 
    AM, PM, am, pm

    mikes0011
    Brainy
    Apr 1, 2022 1:49 PM UTC

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

    The Expression Guru