SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    No more than 8 characters else display error

    Hi Guys,

    How do i check to see if a variable contains 8 numbers. For example.

    If $dob == 8 numbers then
    echo works
    else
    echo wrong

    Has to be numbers and no text, Any help would be great.

    Thanks Guys!

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,747
    Mentioned
    64 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    8,891
    Mentioned
    138 Post(s)
    Tagged
    2 Thread(s)
    I'd use ctype_digit instead of is_int, in case it comes from $_POST of $_GET and is thus a string, and not an int, but numeric nonetheless
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  4. #4
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi StarLion,

    Hope your well today. I've tried that but keep getting the is not integer error.

    PHP Code:
    <?php
    $dob
    =$_GET['dob'];

    if (
    is_int($dob)) {
        echo 
    "is integer\n";
    } else {
        echo 
    "is not an integer\n";
    }

    ?>
    /testdob.php?dob=4

    Thanks

  5. #5
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by ScallioXTX View Post
    I'd use ctype_digit instead of is_int, in case it comes from $_POST of $_GET and is thus a string, and not an int, but numeric nonetheless
    Ah, I'll try this then since thats what I'm doing

    Thank you.

  6. #6
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys, EDITED: Fixed it

  7. #7
    @php.net Salathe's Avatar
    Join Date
    Dec 2004
    Location
    Edinburgh
    Posts
    1,396
    Mentioned
    54 Post(s)
    Tagged
    0 Thread(s)
    Is 87654321 an acceptable value for $dob?
    Salathe
    Software Developer and PHP Manual Author.

  8. #8
    SitePoint Addict
    Join Date
    Mar 2011
    Location
    Manchester, UK
    Posts
    226
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Salathe View Post
    Is 87654321 an acceptable value for $dob?
    No its not but its just an example

    I've already coded it to ensure the date entered is valid

    Thanks for pointing it out though.
    You're Help Does Not Go Unnoticed, I have So Far Donated £25 GBP
    To Cancer Research UK As A Thank You To All The SitePoint
    Members That Have Helped Me In The PHP Forum Thank You!


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
  •