SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    filtering input box

    Hi,

    Does anyone knows here how to filter a certain input on the web inputbox? Let say, I want to filter an input which is equal to 9 digits only. If user inputted below or above the required digits. They would prompted that they inputted an invalid number. Likewise, if they entered which contains text strings, it would also prompted an invalid input. Is that possible using if statement or any equivalent commands on PHP scripts.

    Please help me!!!!

    Thanks....

  2. #2
    SitePoint Evangelist cronsrcs's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    www.silver-rocket.com
    Creative Solutions for this planet and beyond...
    www.onelifeonebus.com
    Fear fading away, not burning out.

  3. #3
    SitePoint Evangelist cronsrcs's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    500
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Untested:

    PHP Code:
    if(!eregi("([0-9]{9})",$input))
    {
       
    //its not valid

    Or I guess you could try
    PHP Code:
    if( (!is_numeric($input)) || (strlen($input)!=9) )
    {
       
    //its not a number and its not 9 digits long

    www.silver-rocket.com
    Creative Solutions for this planet and beyond...
    www.onelifeonebus.com
    Fear fading away, not burning out.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi cronsrcs,

    Is there any otherway, I'm new with php and I want it to implement right away. For now, I have enough time to explicate or study the regular expressions. I am thinking that it is possible in If statement to filter such requirements.

    Thanks....

  5. #5
    SitePoint Enthusiast
    Join Date
    Jul 2006
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi cron,

    You're the best!!! Thank you so much.....


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
  •