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

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!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (2,503)