Hi all i have a post value which i am checking to see if its been posted it has atleast 4 numbers (digits) this works perfect.
if (isset($_POST['year']) &&
!preg_match('/([0-9]{4})/i', stripslashes(trim($_POST['year']))) ) {
now i want to check that the value is greater or = to a vairable and not sure how to achive what i need
i tried the below with no luck
$yearOff = date("Y")-150;
echo $yearOff;
if (isset($_POST['year']) &&
!preg_match('/([0-9]{4})/i', stripslashes(trim($_POST['year'])))
&& $_POST['year'] > $yearOff ) {
$ageerrors[] = '<span class="error">
You forgot enter your birth YEAR</span>';
}
Explanation:
Input is set (not
nullwhich would be false), then it must have a string-length of four and finally it’s numerical value must be higher or equal$yearOff.I assigned the value of the input to it’s own variable as well, because you only need to take it once out of
$_POST.As all these conditions are negated, I used the or
||operator. Naturally the same can be expressed non-negated and with and:To better debug this, the next step is to assign the validity to a variable as well:
Hope this is helpful.