how to validate a number

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • WindAndWaves

    #1

    how to validate a number

    Hi Gurus

    Excuse my ignorance.... I am just learning PHP and I am loving it - I am
    just amazed by what it has to offer - it seems endless.

    Anyway, I want to ask something very simple. How can I for a value to be a
    number between 0 and 99 or 0 and 99999?

    I have included a code snippet of where I would like to add it.

    TIA
    - Nicolaas

    // check MIN AND MAX RATE for validity (between 1 and 100,000)

    if ($min_rate >0 && $max_rate <99999) {

    $sql .= " AND (a.rateMin >=$min_rate AND a.rateMax <=$max_rate) ";

    $humanSQL .= "<LI>the tariffs range is between (in New Zealand
    dollars): $min_rate and $max_rate </LI>";

    }






  • News Me

    #2
    Re: how to validate a number

    WindAndWaves wrote:[color=blue]
    > Hi Gurus
    >
    > Excuse my ignorance.... I am just learning PHP and I am loving it - I am
    > just amazed by what it has to offer - it seems endless.
    >
    > Anyway, I want to ask something very simple. How can I for a value to be a
    > number between 0 and 99 or 0 and 99999?[/color]

    This is explained in this section

    XCI. Regular Expression Functions (Perl-Compatible)

    of the PHP manual.

    NM

    --
    convert uppercase WORDS to single keystrokes to reply

    Comment

    • Sean

      #3
      Re: how to validate a number

      On Mon, 17 Jan 2005 21:12:23 +1300, "WindAndWav es" <access@ngaru.c om>
      reverently intoned upon the aether:
      [color=blue]
      > Hi Gurus
      >
      > Excuse my ignorance.... I am just learning PHP and I am loving it - I am
      > just amazed by what it has to offer - it seems endless.
      >
      > Anyway, I want to ask something very simple. How can I for a value to be a
      > number between 0 and 99 or 0 and 99999?
      >
      > I have included a code snippet of where I would like to add it.
      >
      > TIA
      > - Nicolaas
      >
      > // check MIN AND MAX RATE for validity (between 1 and 100,000)
      >
      > if ($min_rate >0 && $max_rate <99999) {
      >
      > $sql .= " AND (a.rateMin >=$min_rate AND a.rateMax <=$max_rate) ";
      >
      > $humanSQL .= "<LI>the tariffs range is between (in New Zealand
      > dollars): $min_rate and $max_rate </LI>";
      >
      > }
      >[/color]

      Try the routines at the following link:



      The code inside them is reasonably well commented.

      I would also suggest reading the following info as a starting place
      unless you are already comfortable with handling SQL injection and XSS
      issues.

      The Open Web Application Security Project® (OWASP) is a nonprofit foundation that works to improve the security of software through open-source tools, expert education, and collaborative innovation.


      hope this helps,

      Sean


      "In the End, we will remember not the words of our enemies,
      but the silence of our friends."

      - Martin Luther King Jr. (1929-1968)

      Photo Archive @ http://www.tearnet.com/Sean
      Last Updated 29 Sept. 2004

      Comment

      • Narcis Radu

        #4
        Re: how to validate a number

        WindAndWaves wrote:[color=blue]
        > Hi Gurus
        >
        > Excuse my ignorance.... I am just learning PHP and I am loving it - I am
        > just amazed by what it has to offer - it seems endless.
        >
        > Anyway, I want to ask something very simple. How can I for a value to be a
        > number between 0 and 99 or 0 and 99999?
        >
        > I have included a code snippet of where I would like to add it.
        >
        > TIA
        > - Nicolaas
        >
        > // check MIN AND MAX RATE for validity (between 1 and 100,000)
        >
        > if ($min_rate >0 && $max_rate <99999) {
        >
        > $sql .= " AND (a.rateMin >=$min_rate AND a.rateMax <=$max_rate) ";
        >
        > $humanSQL .= "<LI>the tariffs range is between (in New Zealand
        > dollars): $min_rate and $max_rate </LI>";
        >
        > }
        >
        >
        >
        >
        >
        >[/color]
        Hi there!

        I prefer to use it in this way:
        if (is_numeric($mi n_rate) && $min_rate >0 && $max_rate <99999)

        sometimes could be some white spaces so you can use
        is_numeric(trim ($min_rate))

        Narcis

        Comment

        Working...