|
-
Dec 25th, 2002, 09:30 AM
#1
Thread Starter
New Member
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...
-
Dec 25th, 2002, 05:24 PM
#2
Stuck in the 80s
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.
-
Dec 26th, 2002, 07:11 AM
#3
New Member
...But better to use JavaScript to check it - much faster
Sincerely,
Sergey Booyny
AlarIT programmer
http://www.AlarIT.com
-
Dec 26th, 2002, 08:35 AM
#4
Thread Starter
New Member
merci 
i will take the php source... i don't like java =)
-
Dec 26th, 2002, 07:53 PM
#5
Stuck in the 80s
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...
-
Dec 28th, 2002, 01:28 PM
#6
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|