PHP Classes

Simple Date Validator: Simple date string validation

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 132 All time: 9,329 This week: 660Up
Version License PHP version Categories
date_validator 1.0.0GNU Free Document...5PHP 5, Time and Date, Validation
Description 

Author

This is a simple class for date string validation.

It takes a given date string and a format string as parameters.

The class can reformat the given date using the given format and compares the original date with the formatted date to determine if the date is valid.

This simple class Validates date strings as a valid date, returning true or false on each test case

Picture of johno dread
Name: johno dread <contact>
Classes: 7 packages by
Country: United States United States
Innovation award
Innovation award
Nominee: 1x

Example

$validdate = new datevalidator();

$validdate->pre( $validdate->validate('2012-02-28 12:12:12')); # true


$validdate->pre($validdate->validate('2012-02-30 12:12:12')); # false
$validdate->pre($validdate->validate('2012-02-28', 'Y-m-d')); # true
$validdate->pre($validdate->validate('28/02/2012', 'd/m/Y')); # true
$validdate->pre($validdate->validate('30/02/2012', 'd/m/Y')); # false
$validdate->pre($validdate->validate('14:50', 'H:i')); # true
$validdate->pre($validdate->validate('14:77', 'H:i')); # false
$validdate->pre($validdate->validate(14, 'H')); # true
$validdate->pre($validdate->validate('14', 'H')); # true

$validdate->pre($validdate->validate('2012-02-28T12:12:12+02:00', 'Y-m-d\TH:i:sP')); # true
//# or
$validdate->pre($validdate->validate('2012-02-28T12:12:12+02:00', DateTime::ATOM)); # true

$validdate->pre($validdate->validate('Tue, 28 Feb 2012 12:12:12 +0200', 'D, d M Y H:i:s O')); # true
//# or
$validdate->pre($validdate->validate('Tue, 28 Feb 2012 12:12:12 +0200', DateTime::RSS)); # true
$validdate->pre($validdate->validate('Tue, 27 Feb 2012 12:12:12 +0200', DateTime::RSS)); # false


  Files folder image Files (2)  
File Role Description
Plain text file datevalidator.php Class main class
Accessible without login Plain text file Tests.php Example Example

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:132
This week:0
All time:9,329
This week:660Up