cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
pchristou
Regular Visitor

Data Validate for Date Text field and Time Text field

Good afternoon,

I have this data validation that another member of the community suggested for my data that works perfectly (And a big thank you to the guy!) :

If(!IsMatch(DataCardValue37.Text,"\d{4}-\d{2}-\d{2}"),
Notify("Please input date in YYYY-MM-DD format!",NotificationType.Error)
)

However, I would like to modify it so that each digit is within a certain range. For example, the first digit of the year should always be a 2 while the second should be 0 and for example, the first digit of the month should always be a 0 or a 1 and for the day 0, 1, 2, or 3. I just wanted to give you a couple of examples to understand the kind of data validation I would like for individual digits.

Any suggestions?

Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @pchristou,

What a coincidence!

Do you want to validate the certain date format using regular expression?

Please modify your formula as below:

If(
    !IsMatch(
    DataCardValue37.Text,
    "[2]\d{3}-(0[1-9]|1[0-2])-[0-3]\d{1}"
    ),
    Notify("Please input date in YYYY-MM-DD format!",NotificationType.Error)
)

Here is the explanation of splitting one by one:

[2]\d{3} // The first digit always starts with 2,so the left number of digits you could input is 3 instead of 4 
(0[1-9]|1[0-2])// The month digit always starts with 0 or 1
[0-3]\d{1}// The day digit always starts with 0, 1, 2, or 3

Hope we could solve this successfully as before.

Best Regards,
Qi

View solution in original post

3 REPLIES 3
Drrickryp
Super User
Super User

@pchristou 

I suggest that you use a datepicker for dates and 2 dropdowns for hours and minutes respectively.  This way you can control how the user inputs date and time data. see @CarlosFigueira 's solution here:   https://powerusers.microsoft.com/t5/Building-Power-Apps/Date-hour-minute-picker-current-date-hour-an... 

The less flexibility you give users with regard to entering data the better. 

pchristou
Regular Visitor

I have a lot of trouble with date pickers when I try to pass the value in as text for some reason and that is why I made it a text field.

Hi @pchristou,

What a coincidence!

Do you want to validate the certain date format using regular expression?

Please modify your formula as below:

If(
    !IsMatch(
    DataCardValue37.Text,
    "[2]\d{3}-(0[1-9]|1[0-2])-[0-3]\d{1}"
    ),
    Notify("Please input date in YYYY-MM-DD format!",NotificationType.Error)
)

Here is the explanation of splitting one by one:

[2]\d{3} // The first digit always starts with 2,so the left number of digits you could input is 3 instead of 4 
(0[1-9]|1[0-2])// The month digit always starts with 0 or 1
[0-3]\d{1}// The day digit always starts with 0, 1, 2, or 3

Hope we could solve this successfully as before.

Best Regards,
Qi

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

365 EduCon 768x460.png

Microsoft 365 EduCon

Join us for two optional days of workshops and a 3-day conference, you can choose from over 130 sessions in multiple tracks and 25 workshops.

Users online (1,764)