PHP Code Date of Birth - Php

How to check your date of birth format is correct or not?

Snippet Code

Rate this page :
  [ 0 votes]

Use the sample PHP code to validate your date of birth format. Call function dob() with your date of birth to check the given dob format is correct or wrong.

<?php function dob($date) { $dregex = '/^(19|20)\d\d[\-\/.](0[1-9]|1[012])[\-\/.](0[1-9]|[12][0-9]|3[01])$/'; if (preg_match($dregex, $date)) { return true; } } $result = dob("1915-12-10"); if($result=='1') { echo 'Your date of birth format is correct!'; } else{ echo "Your date of birth doesn't match the YYYY-MM-DD required format."; } ?>


Ask Questions

Ask Question