cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
choco_01
Frequent Visitor

Check if a manually entered date is valid

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

 

8 REPLIES 8
NandiniBhagya20
Solution Sage
Solution Sage

Hi @choco_01 ,
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))


Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.

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
Community Champion
Community Champion

Hey @choco_01 

 

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/1108...

 

 

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

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.


Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.

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

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

 


Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.

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

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.


Did you like my post? Please give it a thumbs up! Did I resolve your issue? Please click Accept as Solution to close the topic and so other members of the community can find solutions more easily.

Helpful resources

Announcements
Microsoft 365 Conference – December 6-8, 2022

Microsoft 365 Conference – December 6-8, 2022

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Difinity Conference 2022

Difinity Conference 2022

Register today for two amazing days of learning, featuring intensive learning sessions across multiple tracks, led by engaging and dynamic experts.

European SharePoint Conference

European SharePoint Conference

The European SharePoint Conference returns live and in-person November 28-December 1 with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

Power Apps Ideas

Check out the New Ideas Site

We are excited to announce a new way to share your ideas for Power Apps!

Top Solution Authors
Top Kudoed Authors
Users online (5,212)