Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old July 27th, 2004, 12:16 AM
Friend of Wrox
Points: 1,288, Level: 14
Points: 1,288, Level: 14 Points: 1,288, Level: 14 Points: 1,288, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: Stockholm, Sweden
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default Validation of Form

I have a user form in which a user can submit his information. As there are different feilds in the form and I want to restrict a user to enter only correct values in the feilds eg in
Zip code user can only enter numbers and cannot enter any other value. If user press any other key a message is diplayed that please enter only legal values
Can any one help me in this regard? I will be great ful to him.
Thnks in advance







Numan
--------------------------------------------------
Love is the most precious thing of this world. So find and grab it!
__________________
(*_*)

Numan
--------------------------------------------------
It is not important what you get But important is  how you got it
  #2 (permalink)  
Old July 27th, 2004, 01:32 AM
Friend of Wrox
Points: 1,288, Level: 14
Points: 1,288, Level: 14 Points: 1,288, Level: 14 Points: 1,288, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: Stockholm, Sweden
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default

 v

Numan
--------------------------------------------------
Love is the most precious thing of this world. So find and grab it!
  #3 (permalink)  
Old July 27th, 2004, 03:34 AM
Friend of Wrox
 
Join Date: Jul 2003
Location: , , United Kingdom.
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Numan,

This should do the trick...

Code:
function ForceInt(pField){
    var exp = /[^\d]/;
    var value = pField.value;
    if(exp.test(value)){
        alert("Please enter a numeric value");
        pField.value = value.replace(exp, "");
    }    
}

...

<input id="myInput" name="myInput" type="text" onkeyup="ForceInt(this);" />

HTH,

Chris
  #4 (permalink)  
Old July 31st, 2004, 01:39 AM
Friend of Wrox
Points: 3,558, Level: 25
Points: 3,558, Level: 25 Points: 3,558, Level: 25 Points: 3,558, Level: 25
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: California, USA
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Ur function could be like this also:
Code:
    function NumeralsOnly(elem)
    {
        var key;
        if (window.event)
            key = window.event.keyCode;
        else if (e)
            key = e.which;
        if(key >=48 & key < 57)
            return true;
        else
            return false;
    }// NumeralsOnly


Always:),
Hovik Melkomian.
  #5 (permalink)  
Old August 2nd, 2004, 05:54 AM
Friend of Wrox
Points: 1,288, Level: 14
Points: 1,288, Level: 14 Points: 1,288, Level: 14 Points: 1,288, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: Stockholm, Sweden
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default

Dears I want to add floating values which also contain commas like

10,200.00

How can I check for this

Numan
--------------------------------------------------
Love is the most precious thing of this world. So find and grab it!
  #6 (permalink)  
Old August 2nd, 2004, 03:49 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: High Wycombe, UK, United Kingdom.
Posts: 344
Thanks: 0
Thanked 1 Time in 1 Post
Default

check out Regular Expressions (http://builder.com.com/article.jhtml...30224gcn01.htm)


Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
form validation EmWebs Dreamweaver (all versions) 6 January 23rd, 2007 10:01 AM
Form Validation Stanny Access VBA 5 December 20th, 2005 08:13 PM
Form not refreshing after form validation Mimi Javascript How-To 0 August 25th, 2003 03:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.