Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> How Do I Enter Only Numbers In A Form?
kvarnerexpress
post May 14 2005, 09:52 PM
Post #1


Super Member
*********

Group: Members
Posts: 407
Joined: 13-December 04
Member No.: 2,696



i have a form with a few fields such as zip and phone. i only want the user to type in those fields numbers and not letters, and if the user enters letters, then the form will warn the user somehow to only enter number.
is there a function that will accomplish this or how is something like this accomplished?
what code would i have to use?
any help would be greatly appreciated.
thanks
__________________
Kvarnerexpress
Go to the top of the page
 
+Quote Post
cse-icons
post May 15 2005, 08:14 AM
Post #2


Super Member
*********

Group: Members
Posts: 351
Joined: 19-October 04
From: India
Member No.: 1,824



Hi kvarnerexpress,

The following javascript function can be used on each key press to verify if it is a digit. else you can show an alert box indicating only digits are allowed. You can extend this function to incorporate more features as u like, this is just to give u a start...

CODE
function isNumeric(n)
{
    if((n > 47) && (n <  58))  
   {      
        return true;  
    }      
    return false;
}


btw a more useful javascript function that u can use after customizing is available at:

http://www.shiningstar.net/articles/articl...ic.asp?ID=ROLLA

Hope it helped u...

Cheers.

Go to the top of the page
 
+Quote Post
Mike
post May 15 2005, 12:43 PM
Post #3


Owner of Sub-Zero
********

Group: Members
Posts: 159
Joined: 17-November 04
Member No.: 2,325



^ That's a nice script right there! You could also use PHP to make sure it is all numbers, but I'm not really sure how... It would probably be something like this though:

CODE


<?php

$zipcode = $_POST['zipcode'];

if(!preg_match([0-9],$zipcode))
{
echo '<b>Your zip code is only numbers!</b>';

exit;
}

if(strlen($zipcode) > 6 || strlen($zipcode) < 6)
{
echo '<b>Your zip code is 6 characters long!</b>';

exit;
}

?>
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Free Windowsxp Sp2 Cd From Microsoft(10)
  2. Form To Php Mail. Attachment(12)
  3. Memorise Large Numbers(7)
  4. How To Make A Search Form And Php Code?(9)
  5. Have Diferences Of Performance Form Ps2 Full Console To Mini-ps2?(7)
  6. What Are Imaginary Numbers(13)
  7. Problem With Java Script Popup Form(1)
  8. My Idea For A Form Of Government(24)
  9. Sms With Text As Sender Address And Not Numbers!(1)
  10. Whats The Best Form Of Karate For Fitness/defence?(2)
  11. Free Hosting Request Form [denied](1)
  12. Free Hosting Request Form [denied](1)
  13. Html Application Form(6)
  14. Most Efficient Code To Get Prime Numbers(7)
  15. Best Way To Protect Html Form Fields(3)
  1. Add A Javascript Feedback Form On Your Web Page(6)
  2. Super Smash Bros. Brawl – New Challengers(2)
  3. Php Ftp Upload Form(0)
  4. What Happens When You Enter A Website And Hit Enter ?(0)
  5. Controlling Differents Keypresses In A Single Form(0)
  6. I Liked This Form Builder(4)
  7. Updating Php File Through A Web Form(5)
  8. Brand New Motherboard Form Factor Coming Out?(2)
  9. I Keep Seeing The Same Numbers Everywhere(11)
  10. I Need Help(7)
  11. Index In A Mysql Database(3)
  12. Phpmyadmin Error(4)
  13. Form Not Returning Correct Email Address(5)


 



- Lo-Fi Version Time is now: 16th May 2008 - 06:09 PM