|
|
|
|
![]() ![]() |
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 |
|
|
|
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. |
|
|
|
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; } ?> |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 16th May 2008 - 06:09 PM |