-
Notifications
You must be signed in to change notification settings - Fork 58
Date validation (non existing dates...) #130
Comments
Update... Sorry, just woke up ... and realising now that I already asked you this Q a while ago ... But this one seems to work (at least, for dd/MM/yyyy) i'm certainly NO PRO with regExpr, so that's why I'm just suggesting this ... Grtz, |
Yes that's right, for the dates I only validate the structure of it and not necessarily the date itself. I am using regular expression indeed and if you do find a better regex, then I can replace it (which you did find). Thanks for the link, I will take a look at it later after work, seems to work quite good at first look :) |
I took a look at it and even though it does cover well the calendar dates, it has flaws. Or at least, to my eyes... You can enter 1 or 2 digits (day, month) and enter 2 or 4 digits for the year. That is the part that I'm not crazy about, especially since all my error messages strictly says to put 2 digits at all time. 01/1/01 This is of course January 1st of 2001. I don't know about you, but I wouldn't accept this in my applications. I find this error prone. However, even if I'm not an expert on Regex either I tried to give it a shot and modify the expression to accept only 2 digits (dd/mm) and 4 digits (yyyy) and I came out with the following /^(?:(?:31(\/|-|\.)(?:0[13578]|1[02]))\1|(?:(?:29|30)(\/|-|\.)(?:0[1,3-9]|1[0-2])\2))(?:(?:1[6-9]|[2-9]\d)?\d{2})$|^(?:29(\/|-|\.)02\3(?:(?:(?:1[6-9]|[2-9]\d)?(?:0[48]|[2468][048]|[13579][26])|(?:(?:16|[2468][048]|[3579][26])00))))$|^(?:0[1-9]|1\d|2[0-8])(\/|-|\.)(?:(?:0[1-9])|(?:1[0-2]))\4(?:(?:1[6-9]|[2-9]\d)?\d{4})$/ It seems to work with these modifications, but I did really brief tests. You might want to do a bit deeper tests to make sure it's all good. Other suggestions, while looking at the list of my current available Validators, I see that I have At the end, it would be nice converting this nice Regex (that you found) for US dates as well. Though it might be tricky, I think it's doable. even if I'm not a fan of US dates (I'm from Canada, we use metric but also US stuff since they are so close to us lol). My preferred date format is still ISO. So that might take me a while to do all the changes. Feel free to comments. |
Hi Ghiscoding, Thanks for your extended feedback. Highly appreciated ! Lucky me, we agreed to to accept only long euro dates... I certainly agree with you that I wouldn't accept 01/01/01 in any application. (But other devs maybe will accept this, or are having a reason to accept this in their application) So I certainly like your idea of implementing a 'date_euro' as well. As written before, I'm certainly NOT expert in RegEx, but if you can tell me how I can test them, I certainly willing to help you ! Keep in touch ! Promise ! PS.: it seems that your modified RegEx (accepting 4 digits in case of 2or4) seems to work fine (for my needs) Thanks in advance for your reply and the great support ! Grtz, |
Bonjour Johnny, Thanks for the response, I think that I got Euro & US Dates working with this new way of validating (all base of the same regex you found). It was quite some work to modify it but it seems that I managed, I'll have to do more tests to make sure. However I can't implement it just yet as I would like to have all 3 type of dates working (Euro, US and ISO), so I'm only left with ISO to figure out. Hmm thinking about it, I actually have more work, since I have only done the Since I want to do all or nothing, it might be somewhere next week until I can publish a new version. BTW, je suis au Qc, alors je parle Francais aussi ;) D'ailleurs c'est moi qui a fait les traductions francaise :) |
Hello Ghislain, Well, I'm born and raised up in the Northern part of Belgium (Flanders), so my mother tongue is Dutch. Thanks a lot for your effort about the date-'problem' ! Second one is a link to a complete, 150 pages book Gonna start studying now :) Keep in touch, Grtz, |
BTW ... This is an interesting Online RegEx Tester Grtz, |
Hi there, I made a new version 1.5.6 for this and also created 2 new validators ( NOTE: I deprecated all the |
BTW not sure if you did or not, but you can support by clicking on ⭐ (star on stop). I like to know many users have it installed. Ohh and I don't believe that Cheers |
Hi Ghislain, Thanks for the update ! Currently fighting with a deadline, but the Dutch translation will be there ASAP ! Grtz, |
Just contacted a friend of mine. Grtz, |
Sounds great, thanks :) |
Hi Sir,
Congraz with the development of this great validator.
Though, it seems there is still a small problem with the dates...
I'm using the date_euro_long validator
Giving 31/04/2001 (April 31st) seems to be accepted as a valid date (though April has max 30 days...)
Testing a bit further ...
30/02/1968 (Feb 30th 2001) seems also to be accepted as a valid date, though Feb has only 28 or 29 days (leap years)...
Any workaround about this ?
Thanks in advance for your reply,
Johnny Driesen
Belgium
The text was updated successfully, but these errors were encountered: