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!
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.
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.
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-and-minute/td-p/119799
The less flexibility you give users with regard to entering data the better.
WarrenBelz
791
Most Valuable Professional
MS.Ragavendar
410
mmbr1606
275
Super User 2025 Season 1