web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Check if a manually en...
Power Apps
Unanswered

Check if a manually entered date is valid

(0) ShareShare
ReportReport
Posted on by

Hello,

 

In power Apps I have a date picker : 

choco_01_0-1669291971472.png

And I want to show a validation erreor ounce the user enters an invalid date manually like this :

choco_01_1-1669292032957.png

Because when I enter manually data like this, it doesn't show any kind of error and after I submit my form the invalid manually entered date isn't saved which means somehow the power apps knows it is not correct... Is there a way that power apps tells me the value is not good before submitting ounce I enter the wrong date manually and click outside the text box please ?

 

Thank u

 

Categories:
I have the same question (0)
  • NandiniBhagya20 Profile Picture
    4,667 Super User 2024 Season 1 on at

    Hi @Anonymous ,
    When you use Patch or SubmitForm function, you can do check if the format is valid or not - 

    If(IsBlank(DatePicker1.SelectedDate),Notify("message", NotificationType.Error), SubmitForm(FormName))

  • Community Power Platform Member Profile Picture
    on at

    I do not want to check if the field is blank or not, but the "how" power apps resets it to blank after finding that the format is not valid. Because I can submit my form if by default the date value is blank but if it is invalid I sould not be able to submit and a validation error should appear...

    My problem is how to check if the manually entered date is invalid, any solution please ?

  • Sundeep_Malik Profile Picture
    6,484 on at

    Hey @Anonymous 

     

    Found a previous post which has similar thing that you require, though the solution has not been accepted but you can try to make a formula similar to this:

     

    If(!IsMatch(Text(valueTerminationDateED.SelectedDate), "\d{1,2}/\d{1,2}/\d{4}") || Value(First(Split(Text(valueTerminationDateED.SelectedDate), "/")).Result)>12 || Value(Last(FirstN(Split(Text(valueTerminationDateED.SelectedDate), "/"))).Result)>31, 
     "Please input correct format datetime",
     ""
    )

     

    https://powerusers.microsoft.com/t5/Building-Power-Apps/Datepicker-Validation-check-format/td-p/1108914

     

     

    Rest I will try it on my end if it works. 

  • NandiniBhagya20 Profile Picture
    4,667 Super User 2024 Season 1 on at

    If you add any value in the date picker that is not in proper format (date format), the DatePicker.SelectedDate will return blank. Using this you can check whether the date in datepicker is in proper format or not.

  • Community Power Platform Member Profile Picture
    on at

    By default my date is blank so there is times the user can submit without putting in any date

  • NandiniBhagya20 Profile Picture
    4,667 Super User 2024 Season 1 on at

    You can set the IsEditable property to false. By doing so, users will not be able to enter dates, they can only select the date from datepicker

    NandiniBhagya20_0-1669299890867.png

     

  • Community Power Platform Member Profile Picture
    on at

    Not possible because I need to have the possibility to put it manually too. No way to know if the manual value is valid ?

  • NandiniBhagya20 Profile Picture
    4,667 Super User 2024 Season 1 on at

    Well, as far as i have seen, we cannot do that because if you want to check the date format, you will first need to extract the value from datepicker. In case of incorrect date, it returns blank,
    DatePicker1.SelectedDate is returning Blank().
    If we can extract the value from date picker then we can check the format by creating our own formula.

  • powerapp2020 Profile Picture
    4 on at

    Is there a solution now? I am in the same boat as the OG

  • Suggested answer
    josephspengler Profile Picture
    123 on at

    I have a PowerApps form which asks for several dates. I know the preferred solution is to set IsEditable to false and force users to click the calendar. However one of my fields is the Date of Birth. Expecting a user to click the back arrow a month at a time to choose a date in 1970 is unreasonable.

    So I set IsEditable to true, but I of course need to do data validation now. Not just that the date isn't in the future, but also that it's a date at all and not junk like "June" or "Apple" or 99/99/9999.

    Plan A, the simplest way to do this would be OnSubmit for a form, or the equivalent for patch. However I hate the user experience or letting the user enter an invalid value, ignoring it, and then throwing an error later. Why not tell the user they are making a mistake while they are making a mistake?
    In addition, this solution does not work if your date is optional. DatePicker with junk in it returns blank, so the OnSubmit cannot differentiate between an invalid date and no date.

    Plan B, I'll just add some code to the OnChange property of the DatePicker. Except that does not work. If the entered date is not a date, the DatePicker pretends it doesn't exist and does not trigger the OnChange property.

    Plan C, I'll setup some code that looks at the DatePicker property of SearchText or Text and does validation on that. Except that does not work, those properties do not exist.

    Plan D, ditch the DatePicker entirely, use a TextInput control. This is a viable option. If you're short on time, just do this. There are a lot of reasons I don't like this though. It's crazy to me that the best option to enter a date is to not use DatePicker. It does not allow the user to use the calendar. It doesn't give the visual indications of it being a date field.

    Plan E, use both a TextInput and a DatePicker field, tie them together. If this sounds overly complicated it is, but it's the best solution I could come up with. I put the TextInput above the DatePicker, covering most of the DatePicker control except for the Calendar button on the right. Set the default value for both controls to a varDate (can be Blank() or a valid date). Set the OnChange for the DatePicker to Set(varDate,Self.SelectedDate). This will only trigger if they click the calendar icon to change the date since they cannot get to the box to type in it.

    Then in the TextInput in OnChange do the fancy date validation. You can google to find formulas for this. Some people use impressive OnMatch formulas. I opted for a simple:

    Set(varDate,  IfError( DateValue(Self.Text),Blank()));

    This works surprisingly well. If anything it's a bit too lenient. You can type in 2 and it will pick 2/1/2001. But it's great for 12 June 04 or 2004/6/12.

    The really nice part of this is the user can interact with these two fields like they are one field. They can type a date in, then click the calendar to confirm which day of the week it is for example.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard