hi guys!

can somebody write the lines for me:
1. how to make sure that data from $_GET would be all numbers via eregi()

example:
 [code=html]www.domain.com?data=12345[/code]

 so how do i check and make sure that the stuff passed into "data" is a set of numbers ranging from 1-99999999?

  i like the code to look kinda like:
          [code=php]if (eregi ([0-9]{1,99999999})$, $_GET('data')) {[/code]
  1. how about making sure that he submitted data is always a set of 8-digit numbers?

tnx for the help in advance!

    so how do i check and make sure that the stuff passed into "data" is a set of numbers ranging from 1-99999999?

    Check:

    if (1 <= $_GET['data'] && $_GET['data'] <= 99999999)

    2. how about making sure that he submitted data is always a set of 8-digit numbers?

    Check:

    if (ctype_digit($_GET['data']) && strlen($_GET['data']) == 8)

    or

    if (10000000 <= $_GET['data'] && $_GET['data'] <= 99999999)

      Hi,

      I would like to use eregi so i can immediately check if data submitted is in the correct format. In this case, i'd like to make sure the the value for 'kool' is composed of a set of 8-digit numbers.

      // Get bookcode and process data
      	if (eregi('[0-9]{8})$', $_GET['kool'])) {
      		$bookcode = $_GET['ac'];
      
      		// echo the book code
                          ehco 'the book code is ' . $bookcode;
      
      } else { 
      	$bookcode = 'none';
      	               echo 'invalid book code';
      }
      

      I need help. Im new to this. Please tell me what's wrong and how I can fix it.

      Thanks!

        For starters you should change 'ehco' to 'echo'. I'd also recommend using the preg_ family of functions instead of the ereg family. PCRE is a much better standard for defining regular expressions. Here's the manual entry for preg_match()...

        http://us.php.net/manual/en/function.preg-match.php

        And here is how you would match 8 digits....

        if ( preg_match( '/^\d{8}$/', $_GET['kool'] ) )

        Note that case sensitivity is irrelevant when matching digits. Otherwise I would add an 'i' after the slash right before the closing quote in the pattern. That's the PCRE modifier for case-insensitivity.

          I'd probably use a preg_match() (not claiming it's best or fastest, just the way I tend to do things):

          $_GET['data'] = trim($_GET['data']); // get rid of leading/trailing white-space
          if(preg_match('/^\d{8}$/', $_GET['data']))
          {
             // valid 8-digit value
          }
          else
          {
             // not valid
          }
          

            hi guys,

            thanks for your replies. however, aside from making sure that the value is composed of 8-digits, i'd also like to make sure that it is composed of NUMBERS only. How can we do this?

            thanks again in advance

            🙂

              hi,

              tnx for the reply.

              btw, the 'ehco' is a typo. 🙂

              tnx again!

                onairric wrote:

                hi guys,

                thanks for your replies. however, aside from making sure that the value is composed of 8-digits, i'd also like to make sure that it is composed of NUMBERS only. How can we do this?

                thanks again in advance

                🙂

                numbers == digits

                In preg_*() regular expressions, "\d" means any numeric character from 0 through 9. Therefore, '/\d{8}$/' means a string of exactly 8 number (i.e.: digits). Depending on exactly what you want:

                // must be between 10000000 and 99999999:
                if(preg_match('/^[1-9]\d{7}$/', $input))
                {
                   // valid
                }
                
                // must be between 1 and 99999999:
                if(preg_match('/^[1-9]\d{0,7}$/', $input))
                {
                   // valid
                }
                

                  Note: I've merged two threads together here, both started by Onairric, since they were both discussing the same thing. The resulting sequence of posts/replies may therefore be a little confusing.

                    ahhh, sorry about that. tnx for clarifying. =p

                      Write a Reply...