Forum Moderators: coopster
some valid e.g.: 2008/12, 2008/1, 2008/01
invalid examples: 2007/13, 20059/1
so basically i want to make sure tht there are 4 integers bfore the '/' , and there can be two intergers or 1 integer for month which should be less than 13...
Any help would be greatly appreciated....
thanks!
Looks like the way to go would be to explode [uk2.php.net] the var and then do some checks. If you had the full date you could use checkdate [uk2.php.net] to check for a valid date.
To check for digits you can use is_int [uk2.php.net], or the ctype_functions [uk2.php.net] or indeed character classes.
Good luck.
dc
As you want to check the pattern of your date you may want to use a regular expression -
$pattern = '%^\d{4}/(?:0?[1-9]¦1[012])$%';
if(!preg_match($pattern, $input)) {
echo 'Put in a proper date';
}
$this_year = [url=http://uk2.php.net/manual/en/function.date.php]date[/url]('Y'); // 2008
$pattern = "%^$this_year/(?:0?[1-9]¦1[012])$%";