Jump to content

[SOLVED] month validation by name


scarhand

Recommended Posts

im trying to validate whether or not a proper month name was entered in a form

 

heres my script (does not work)

 

the variable $birthmonth refers to a month by name, i.e. November, October, etc.

 

<?php
  if (date("n", $birthmonth) != range(1, 12))
  {
    $errormsg = 'You have specified an invalid month of birth';
  }
?>

Link to comment
https://forums.phpfreaks.com/topic/77732-solved-month-validation-by-name/
Share on other sites

Set up an array of the proper month names and then check whether the entered name is in that array:

<?php
$mnts = array('january','february','march','april','may','june','july','august','september','october','november','december');
if (!in_array(strtolower($birthmonth),$mnts))
     $errormsg = 'You have specified an invalid month of birth';
?>

 

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.