Results 1 to 4 of 4

Thread: Year validation

  1. #1
    Join Date
    Dec 2003
    Posts
    50

    Unanswered: Year validation

    Hi!

    This must be a very basic one.

    I want to check if the year that an user introduces in a text box in a form is valid, that is is an integer value between 1900 and current year.

    What is the best way to do this?

    Thanks for your attention.
    Ah! Não ser eu toda a gente e toda a parte!

  2. #2
    Join Date
    Oct 2003
    Location
    Slovakia
    Posts
    482

    Re: Year validation

    Originally posted by rpOliveira
    Hi!

    This must be a very basic one.

    I want to check if the year that an user introduces in a text box in a form is valid, that is is an integer value between 1900 and current year.

    What is the best way to do this?

    Thanks for your attention.
    if(strlen($year)<5 && is_numeric($year) && $year>=1900 && $year<date("Y")){
    echo "OK";
    } else {
    echo "Bad date!";
    }

  3. #3
    Join Date
    Oct 2003
    Location
    Slovakia
    Posts
    482

    Re: Year validation

    Originally posted by ika
    if(strlen($year)<5 && is_numeric($year) && $year>=1900 && $year<date("Y")){
    echo "OK";
    } else {
    echo "Bad date!";
    }
    And of course: http://www.php.net/docs.php

  4. #4
    Join Date
    Dec 2003
    Posts
    50
    OK. Thanks for your answers.
    Ah! Não ser eu toda a gente e toda a parte!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •