Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Only allow numbers in form entry

Status
Not open for further replies.

smashing

Programmer
Oct 15, 2002
170
US
I know this is probably simple, but I'm still new to PHP so....
I have a form where I ask users to enter a number - if they enter any character then I want them to get a different message. How do I do this ?
 
You have two choices.

You can have JavaScript check the well-formedness of the input at the client side, or have the user submit the form and have PHP do it.

The question "How do I do it in JavaScript?" can best be answered in the JavaScript forum.

For PHP, one possibility is preg_match() ( Want the best answers? Ask the best questions: TANSTAAFL!
 
use the is_numeric() function like this:

if (!is_numeric($data)){
echo "you are a bad boy...numbers only";
}else{
//do something else
} Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top