Results 1 to 10 of 10

Thread: Validation ----

  1. #1
    Join Date
    Aug 2006
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Validation ----

    I cant get these two pieces of my validation to work...

    if I have an IP of 192.168.1.1 -- it fails... it only passes if I have 192.168.111.100 -- a full IP ..... it needs to accept number like 10.1.1.1 etc...
    Code:
    #
           # IP address
           #
           $field       = $ipaddress;
           $field_name  = "<b>IP Address</b>";
           if(  (!$field)
                || strlen($field) < 8 || strlen($field) > 15
                || !preg_match("/[0-9]{3}+[.]{1}+[0-9]{3}+[.]{1}+[0-9]{3}+[.]{1}+[0-9]{3}/", $field, $matches ) 
              )
              {
                 $error_string .= $field_name . " cannot be empty and can only contain numbers 0-9 and periods (ex. 192.168.101.102).<br />";
              }

    this one just always fails...
    Code:
    #
           # check phone
           #
           $field       = $Phone;
           $field_name  = "<b>Phone Number</b>";
           if(  (!$field)
                || strlen($field) == 12 || strlen($field) > 12 
                || !preg_match("/[0-9]{3}+[-]{1}+[0-9]{3}+[-]{1}+[0-9]{4}/", $field, $matches )       
              )
              {
                 $error_string .= $field_name . " must be in 10 digit format (ex. 811-555-1212).<br />";
              }

    can anyone help me out..

  2. #2
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    im not that good at SSI, but thats CGI, not PHP....


    it appears that we only have 1 server side forum.
    should be renamed to SSI...
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Humper View Post
    Code:
    if(  (!$field)
            || strlen($field) < 8 || strlen($field) > 15
            || !preg_match("/[0-9]{3}+[.]{1}+[0-9]{3}+[.]{1}+[0-9]{3}+[.]{1}+[0-9]{3}/", $field, $matches ) 
              )
    Code:
    $field = trim($field);
    $octet = '(?2(?[0-4][0-9]|5[0-5])|(?1[0-9]|[1-9])?[0-9])';
    $dottedOctet = "/^{$octet}(?\\.{$octet}){3}$/";
    
    if (!$field || !preg_match($dottedOctet, $field, $matches)) {
    That isn't necessarily sufficient: there are legal IP addresses that are reserved and shouldn't be encountered in some circumstances.

    Code:
           if(  (!$field)
                || strlen($field) == 12 || strlen($field) > 12 
                || !preg_match("/[0-9]{3}+[-]{1}+[0-9]{3}+[-]{1}+[0-9]{4}/", $field, $matches )
              )
    Code:
    $field = trim($field);
    
    if (!$field || !preg_match('/^[0-9]{3}-[0-9]{3}-[0-9]{4}$/', $field, $matches)) {

    Quote Originally Posted by boxxertrumps View Post
    im not that good at SSI, but thats CGI, not PHP....
    Those are three different things, and what the OP posted is PHP.

    Mike
    Last edited by mwinter; 12-01-2006 at 12:07 AM. Reason: Missed some parentheses

  4. #4
    Join Date
    Aug 2006
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    The phone check works fine now....but the IP check still doesnt work..

    if I enter 192.168.101.123 it fails
    Code:
    #
    	   # check IP
    	   #
    	   #
    	   $field = trim($ip_address);
    	   $field_name  = "<b>IP Address</b>";
    	   $octet = '(?2(?[0-4][0-9]|5[0-5])|(?1[0-9]|[1-9])?[0-9])';
    	   $dottedOctet = "/^{$octet}(?\\.{$octet}){3}$/";
    		
    	   if (!$field || !preg_match($dottedOctet, $field, $matches))
    	   {
                 $error_string .= $field_name . " cannot be empty and can only contain numbers 0-9 and periods (ex. 192.168.101.123).<br />";
           }
    any one know why?

  5. #5
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Quote Originally Posted by mwinter View Post
    [code]
    Those are three different things, and what the OP posted is PHP.
    Mike
    sorry, used to seeing # in cgi scripts.. and aren't CGI & PHP serverside interpreter languages?
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    CGI is not a language. It's a specification to pass various pieces of information to a program, which can then return a file.

    # in SSI has a special meaning; in PHP, it's a single-line comment marker, as it should be in any language designed to be run with an interpreter. The C++-like double slash is preferred.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Humper View Post
    but the IP check still doesnt work..
    Sorry. Four of the question marks should have been followed by a colon:

    Code:
    $octet = '(?:2(?:[0-4][0-9]|5[0-5])|(?:1[0-9]|[1-9])?[0-9])';
    $dottedOctet = "/^{$octet}(?:\\.{$octet}){3}$/";
    Mike

  8. #8
    Join Date
    Aug 2006
    Posts
    65
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default

    this still doesnt allow 192.168.0.1 --- I still get the error code..

    also on 192.168.100.101 -- I still get the error code..


    any ideas?

  9. #9
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    This is intentional. Those are both reserved IPs.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  10. #10
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Humper View Post
    this still doesnt allow 192.168.0.1 --- I still get the error code..

    also on 192.168.100.101 -- I still get the error code..
    The updated regular expression I posted validates both of those as syntactically correct (and they are). However, as Twey wrote, those are part of the private address space and should not normally be expected. If this is for an intranet, fair enough, but the problem isn't with my suggestion.

    Mike

Bookmarks

Posting Permissions

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