wrote this code to check if date is valid, it shou...
# cfml-general
g
wrote this code to check if date is valid, it should check both formats dd/mm/yyyy or mm/dd/yyyy, seems its working for mm/dd/yyyy but failing for dd/mm/yyyy anyone please guide https://trycf.com/gist/c39fc344272a67f5d5985c3effda73d8/acf2021?theme=monokai
a
d
How are you going to know which format is actually being used? Is 01/02/2023 Jan 2 or Feb 1?
g
It’s passed from previous page as mm or dd first And should not this function checks what format it is and then send true or false
d
Does the previous page tell this page which format is being used? I would think it has to, or someone has to decide it will always be one way or the other. Some dates, like the one I mentioned, could be either in either format, resulting in two different dates. If this is user entered data, the form has to be very clear how it should be entered, maybe even with 3 separate labeled fields for month, day and year. If it comes from some other system or calculation, with no human involved, you need a specification for how the system will work, which other code and this page can follow. Make sense?
g
It does and I have input mak enabled but user can enter 35/35/3035 That is not right and javascript needs a lot of code to check that then there I keep yet and whatever
a
but user can enter 35/35/3035
Why? There is a native html date input type https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date or plenty of JS solutions
Or literally have an dropdown select for day, month and year so they pick them separately
g
The field cannot be date type
a
OK - confused 🙂 You have a field to capture a date but want to allow any value?
g
No I have a field but I want to keep it test not a date input field
a
I don't see how you're going to know which format they are entering the date as then to validate against. So all you can do is what I originally posted which is that it is valid for either
dd/mm/yyyy
or
mm/dd/yyyy
but you will have some dates that match both formats (02/03/2023 for example) and you'll have no way to know if that is entered as
dd/mm/yyyy
or
mm/dd/yyyy
.
g
true, my purpose is to stop them from entering invalid dates like 02/31/2024 or 31/02/2024