Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8365623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T12:42:11+00:00 2026-06-09T12:42:11+00:00

Hi all i have a post value which i am checking to see if

  • 0

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>';
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T12:42:12+00:00Added an answer on June 9, 2026 at 12:42 pm
    $yearOff = date("Y")-150;
    echo $yearOff;
    
    $input = @$_POST['year'];
    
    if (!$input || strlen($input) !== 4 || $input < $yearoff) {
        ### MEEEP, ERROR ###
    }
    

    Explanation:

    Input is set (not null which 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:

    if ($input && strlen($input) === 4 && $input >= $yearoff) {
        ### THIS IS CALL OKAY ###
    }
    

    To better debug this, the next step is to assign the validity to a variable as well:

    $inputValid = $input && strlen($input) === 4 && $input >= $yearoff;
    if (false === $inputValid) [
        ### MEEP, ERROR ####
    }  
    

    Hope this is helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a form[method=get] which has a number of checkboxes all have the same
I need to grab all the FIELD and VALUES from a POST. I have
I have a $.getJSON call that's too long to post here. It all works
I have 50 newsletters which all have different email accouts, hex colour codes and
I have a bunch of Rails 3.1 controllers which all have very similar testing
I have a $.post function inside of a loop. All it does it call
I am using Jquery to post a value to a page which should then
first of all this is my first post so maybe the whole description may
I have a POST request which receives a JSON String as a result. The
I have two radio buttons and want to post the value of the selected

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.