scarhand Posted November 17, 2007 Share Posted November 17, 2007 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 More sharing options...
kenrbnsn Posted November 17, 2007 Share Posted November 17, 2007 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 Link to comment https://forums.phpfreaks.com/topic/77732-solved-month-validation-by-name/#findComment-393453 Share on other sites More sharing options...
rarebit Posted November 17, 2007 Share Posted November 17, 2007 Also this usage doesn't work! if (3 == range(1, 12)) { print 'Yes'; } else { print 'No'; } Link to comment https://forums.phpfreaks.com/topic/77732-solved-month-validation-by-name/#findComment-393456 Share on other sites More sharing options...
Barand Posted November 17, 2007 Share Posted November 17, 2007 try if (strtotime("1 $birthmonth") == 0) { echo 'You have specified an invalid month of birth'; } Link to comment https://forums.phpfreaks.com/topic/77732-solved-month-validation-by-name/#findComment-393461 Share on other sites More sharing options...
scarhand Posted November 17, 2007 Author Share Posted November 17, 2007 try if (strtotime("1 $birthmonth") == 0) { echo 'You have specified an invalid month of birth'; } worked like a charm! Link to comment https://forums.phpfreaks.com/topic/77732-solved-month-validation-by-name/#findComment-393470 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.