Author |
Message |
happyslappy
|
Post subject: date validation Posted: Thu May 10, 2007 8:30 pm |
|
|
that was a stupid comment btw |
|
Joined: Wed Mar 03, 2004 12:40 pm Posts: 109345 Location: manchester
|
anyone got out to do this on php - uk date format as well
i first though id take DMY format and convert them to unix epoch but for some reason it turns 31st feb into a date in july
all things lifted off net examples have been far to ott or not worked
also a reg ex for ip`s that works would be good whilst im at it as iv had issue on that as well
_________________
|
|
|
|
|
Chadk
|
Post subject: Re: date validation Posted: Thu May 10, 2007 9:44 pm |
|
|
Bow down to the master |
|
Joined: Thu Aug 12, 2004 12:59 pm Posts: 1840
|
happyslappy wrote: i first though id take DMY format and convert them to unix epoch but for some reason it turns 31st feb into a date in july
You do realise that theres only 28 days in feb?
_________________ Codito Ergo Sum | Even i, who have no clue about social life
|
|
|
|
|
Lemon =GCHQ=
|
Post subject: Posted: Thu May 10, 2007 9:47 pm |
|
|
an unsung hero! |
|
Joined: Tue Jun 29, 2004 1:13 am Posts: 5852 Location: on the run from the boyz i love this city
|
ooooooooooooo ding ding
_________________ "If your going to kill a man, it costs nothing to be polite."- Winston Churchill three and a half foot long??? dude, it could have swallowed you whole! 3jorn=GCHQ=
|
|
|
|
|
GeneralPublic=GCHQ=
|
Post subject: Re: date validation Posted: Thu May 10, 2007 10:16 pm |
|
|
Saints ftw!! |
|
Joined: Fri Apr 23, 2004 6:22 pm Posts: 7877 Location: /dev/null
|
Chadk=GCHQ= wrote: happyslappy wrote: i first though id take DMY format and convert them to unix epoch but for some reason it turns 31st feb into a date in july
You do realise that theres only 28 days in feb?
Not in Ricks world
_________________ Insert unfunny comment here ->
|
|
|
|
|
Sleeper Service=GCHQ=
|
Post subject: Posted: Thu May 10, 2007 11:04 pm |
|
|
Humping a Super Model |
|
Joined: Mon Dec 27, 2004 1:54 pm Posts: 3024 Location: NorLonTon
|
Good place for regular expressions not sure about the php dates q though
http://regexlib.com/Default.aspx
Expression:
^(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])$
Description: RegExp for validating the format of IP Addresses.
Matches: 127.0.0.1|||255.255.255.0|||192.168.0.1
Non-Matches: 1200.5.4.3|||abc.def.ghi.jkl|||255.foo.bar.1
_________________
|
|
|
|
|
FoRcEFiRe
|
Post subject: Posted: Fri May 11, 2007 1:59 am |
|
|
Great balls of fire |
|
Joined: Mon Mar 21, 2005 2:12 am Posts: 756 Location: In the disco inferno
|
|
|
|
|
happyslappy
|
Post subject: erm Posted: Fri May 11, 2007 9:16 am |
|
|
that was a stupid comment btw |
|
Joined: Wed Mar 03, 2004 12:40 pm Posts: 109345 Location: manchester
|
Quote: You do realise that theres only 28 days in feb?
thats my point durrrrr
but people will enter shit in forms so i need to validate it
_________________
|
|
|
|
|
aim_x_here
|
Post subject: Posted: Fri May 11, 2007 9:21 am |
|
|
The Librarian- OOK OOK! |
|
Joined: Mon Mar 08, 2004 12:42 am Posts: 4658 Location: tree
|
This is so we can filter out the under 20's from the forum
So come on Chad, get helping!
_________________ Brother ANg-jung soon-um-bongo (Formerly Aim). Mostly Harmful. Vive La France!I want my sig back!
|
|
|
|
|
Arma
|
Post subject: Posted: Fri May 11, 2007 9:57 am |
|
|
PFY wannabe |
|
Joined: Sun Jan 02, 2005 11:51 pm Posts: 3295 Location: South, but not far south enough :/
|
This one looks ok : http://www.smartwebby.com/PHP/datevalidation.asp
I dont know php very well but with the example given I would do the overall check first, then do month then year, then validate the days so that you can test the days in the month correctly....
Sort of :
Code: $month=substr($strdate,($pos+1),($pos)); $date=substr($strdate,0,($pos)); $year=substr($strdate,($pos+4),strlen($strdate)); } if((($month=09)OR($month=04)OR($month=06)OR($month=11))AND(($date<=0)OR($date>30))){echo "30 days hath september, April June and November, Enter a Valid Date";} {
If you get my meaning
_________________
"I wish my lawn was emo, so it would cut itself...."
|
|
|
|
|
Slayer=GCHQ=
|
Post subject: Posted: Fri May 11, 2007 10:34 am |
|
|
Coming out soon... |
Joined: Mon Dec 26, 2005 12:13 am Posts: 6680 Location: Wales
|
aim_x_here wrote: This is so we can filter out the under 20's from the forum So come on Chad, get helping!
Noooooooooo
Does that mean me??
But what about the Pickle
_________________ Quote: - That boy NEEDS to look at porn, if only to try and fake being interested in women - We could rename it to "slayers love life" but that was dead before it even started
|
|
|
|
|
FoRcEFiRe
|
Post subject: Posted: Fri May 11, 2007 11:27 am |
|
|
Great balls of fire |
|
Joined: Mon Mar 21, 2005 2:12 am Posts: 756 Location: In the disco inferno
|
slaps why not populate the forms with list boxes and let people select dates?
That way if someone selects feb, you can tell the other box to only have 28 values in it. This stops the need for validation as you do it before they even enter it
Box1 Month
Box2 Day
etc
|
|
|
|
|
Caspius=GCHQ=
|
Post subject: Posted: Fri May 11, 2007 11:49 am |
|
|
The Groundkeeper |
|
Joined: Fri Mar 26, 2004 7:59 pm Posts: 6056 Location: UK
|
You tried this one?
http://www.vrooms.net/code.php?cat_select=PHP_Date_Validation&show=Date_Validation_and_Conversion
I expect you know all this, but I don't understand how you get the form data into variables on the php code.
Code: if ( $month==2 ) { if ( $year % 4 != 0 ) $dpm[2] = 28; else if ( $year % 400 == 0 ) $dpm[2] = 29; else if ( $year % 100 == 0 ) $dpm[2] = 28; else $dpm[2] = 29; }
I still don't understand how this works out whether it is a leap year. $dpm is the number of days in the month... I could do with sumat like this for a form I've got..
_________________
|
|
|
|
|
Chadk
|
Post subject: Re: erm Posted: Fri May 11, 2007 12:10 pm |
|
|
Bow down to the master |
|
Joined: Thu Aug 12, 2004 12:59 pm Posts: 1840
|
happyslappy wrote: Quote: You do realise that theres only 28 days in feb? thats my point durrrrr but people will enter shit in forms so i need to validate it
But validation isnt supposed to the the only kind of checking. Regex is to make sure that theres no bug that will eventually corrupt the data, and make it worth all shite.
You do NOT wannahave the user type in like 31-2-2007 in a clear text. But as pointed out, youd wanna use drop-down boxes.
_________________ Codito Ergo Sum | Even i, who have no clue about social life
|
|
|
|
|
happyslappy
|
Post subject: durr Posted: Sat May 12, 2007 6:05 pm |
|
|
that was a stupid comment btw |
|
Joined: Wed Mar 03, 2004 12:40 pm Posts: 109345 Location: manchester
|
yes but in a standard drop downs a user could still select 31 2 2008
thats my point
_________________
|
|
|
|
|
happyslappy
|
Post subject: ops Posted: Sat May 12, 2007 6:14 pm |
|
|
that was a stupid comment btw |
|
Joined: Wed Mar 03, 2004 12:40 pm Posts: 109345 Location: manchester
|
Quote: slaps why not populate the forms with list boxes and let people select dates?
That way if someone selects feb, you can tell the other box to only have 28 values in it. This stops the need for validation as you do it before they even enter it
Box1 Month Box2 Day
thats the day its done soz forcey i didnt see that, but due to having to stick to uk date format i cant see how, other wise it would be easy with php / sessions and dynamically change the days in the form
chadk / slayer please stay out of this thread with your smarty arse comments that mean nothing
again a big thank you to everyone else in here who has tried to be constuctive
_________________
|
|
|
|
|
|