Results 1 to 6 of 6

Thread: how to check if letters are written in a textbox

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Location
    www.mechboxer.de
    Posts
    15

    how to check if letters are written in a textbox

    hi,
    my question ist with what command am i able to check if letters are written in a textbox?!
    my problem is, that i only wnat numbers in this textbox and if letters are written in it, the script has to give out a failure message...
    i hope you can help me!
    thanx a lot...
    -=|www.mechboxer.de|=-

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    There are two ways to do this:

    1) check as the user hits submit and if it's invalid, don't allow them to continue and give an alert error message.
    2) allow them to submit, then check it in PHP and give an HTML error message.

    The 1st one would involved JavaScript, the second PHP. Since this is a PHP forum, I will answer #2.

    If you want only numbers in the textbox, then you can check the $_REQUEST[], $_GET[], or $_POST[] variable using the is_numeric() function:

    Code:
    if (is_numeric($_REQUEST['textboxname'])) === false) {
        die("Only numbers are allowed in textboxname!");
    }
    If you want the 1st one, you would have to check it in JavaScript. I'm not sure how you'd do it, so you might want to check over there.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    New Member
    Join Date
    Sep 2002
    Posts
    14
    ...But better to use JavaScript to check it - much faster

    Sincerely,
    Sergey Booyny
    AlarIT programmer
    http://www.AlarIT.com

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2002
    Location
    www.mechboxer.de
    Posts
    15
    merci
    i will take the php source... i don't like java =)
    -=|www.mechboxer.de|=-

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Stylewriter
    merci
    i will take the php source... i don't like java =)
    It's not Java. It's JavaScript. Two entirely differen't things.

    And I have to agree with him. With the JavaScript, you can check it before the page is even submitted. Less loading, less bandwith, faster results, no possibility of loosing data.

    But if you insist...
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6
    Fanatic Member Gimlin's Avatar
    Join Date
    Dec 2001
    Location
    Hell
    Posts
    734
    do both, some people have JS disabled.

    What I do is make check all feilds with the PHP script, checking it very throughly giving a VERY simple error message.

    JS is where I make the checking rather loose, but very user helpful, detailed error message as well as focusing on the incorrect input box.

Posting Permissions

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



Click Here to Expand Forum to Full Width