PrimitiveType

PHP: check year is in YYYY format using regular expression

<?php $year = $argv[1]; // assume script is called in CLI context with at least one argument passed // OR $year = $_REQUEST['year']; // assume script is requested from a browser and year is passed as GET or POST parameter if (preg_match('/^\d{4}$/', $year)) { echo 'OK' . PHP_EOL; } else { echo 'NOT YYYY' . PHP_EOL; }