cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
guyinkalamazoo
Helper II
Helper II

RegEx for DateTime in 24-hour format

I do not like the standard datetime picker from the PowerApps toolbox.  So instead I would like to use just a standard textbox with some RegEx.  For some reason when I run this in the textbox OnChange I always am getting the notification warning.  Can I get another pair of eyes on this and see what might be wrong?  

 

If(
        !IsMatch(txtClearanceDateTime.Text, "^([1-9]|([012][0-9])|(3[01]))[- /.]([0]{0,1}[1-9]|1[012])[- /.]\d\d\d\d (20|21|22|23|[0-1]?\d):[0-5]?\d$,"),
        Notify("You entered an invalid date/time format, please enter value in mm/dd/yyyy hh:mm format", NotificationType.Warning);Reset(txtClearanceDateTime)
    )
1 ACCEPTED SOLUTION

Accepted Solutions
v-bofeng-msft
Community Support
Community Support

Hi @guyinkalamazoo :

The key is that there is an extra comma at the end of your regular expression.

If(
!IsMatch(txtClearanceDateTime.Text, "^([1-9]|([012][0-9])|(3[01]))[- /.]([0]{0,1}[1-9]|1[012])[- /.]\d\d\d\d (20|21|22|23|[0-1]?\d):[0-5]?\d$,"),
Notify("You entered an invalid date/time format, please enter value in mm/dd/yyyy hh:mm format", NotificationType.Warning);Reset(txtClearanceDateTime)
)

Please try:

If(
        !IsMatch(txtClearanceDateTime.Text, "^([1-9]|([012][0-9])|(3[01]))[- /.]([0]{0,1}[1-9]|1[012])[- /.]\d\d\d\d (20|21|22|23|[0-1]?\d):[0-5]?\d$"),
        Notify("You entered an invalid date/time format, please enter value in mm/dd/yyyy hh:mm format", NotificationType.Warning);Reset(txtClearanceDateTime)
    )

36.gif

 Best Regards,

Bof

View solution in original post

1 REPLY 1
v-bofeng-msft
Community Support
Community Support

Hi @guyinkalamazoo :

The key is that there is an extra comma at the end of your regular expression.

If(
!IsMatch(txtClearanceDateTime.Text, "^([1-9]|([012][0-9])|(3[01]))[- /.]([0]{0,1}[1-9]|1[012])[- /.]\d\d\d\d (20|21|22|23|[0-1]?\d):[0-5]?\d$,"),
Notify("You entered an invalid date/time format, please enter value in mm/dd/yyyy hh:mm format", NotificationType.Warning);Reset(txtClearanceDateTime)
)

Please try:

If(
        !IsMatch(txtClearanceDateTime.Text, "^([1-9]|([012][0-9])|(3[01]))[- /.]([0]{0,1}[1-9]|1[012])[- /.]\d\d\d\d (20|21|22|23|[0-1]?\d):[0-5]?\d$"),
        Notify("You entered an invalid date/time format, please enter value in mm/dd/yyyy hh:mm format", NotificationType.Warning);Reset(txtClearanceDateTime)
    )

36.gif

 Best Regards,

Bof

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Microsoft Ignite 768x460.png

Find your focus

Explore the latest tools,training sessions,technical expertise, networking and more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,624)