• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

isNaN

 
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello I want to ensure that the values in my text boxes are either numeric or non numeric.  For example, in my document.forms[0].FirstName.value, I want to make sure only non numeric values are entered.  My book only shows me how to do it by creating a new function, but I want to place it in my current function.  This is what my book says:



how do I use isNaN is my function?

 
author & internet detective
Posts: 40747
827
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Daniel,
Which field do you want to validate? Can you try adding the if statement from the function in that section?
 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jeanne Boyarsky wrote:Daniel,
Which field do you want to validate? Can you try adding the if statement from the function in that section?



I am going to validate all the forms, but I would like to start with the first and last name, and the zip code.  If I add the if statement to my function how do I do it? Is this correct?

 
Jeanne Boyarsky
author & internet detective
Posts: 40747
827
Eclipse IDE VI Editor Java
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well not first/last name as they aren't numbers.

Take a look at your existing validation:


It is similar to, but not the same as your proposed one:


In particular, you should make a few changes:
  • Get rid of the return true. If validation passes, you want more validations to run after rather than returning false
  • Edit the message "You must enter a numberic value!" to be more specific. How does the user know which field?
  • Either rename the numberCheck variable to make it clear which field it is more or get rid of it all together. You can just say if (isNaN(document.forms[0].ZipCode.value))
  •  
    Daniel Martos
    Ranch Hand
    Posts: 126
    1
    • Mark post as helpful
    • send pies
      Number of slices to send:
      Optional 'thank-you' note:
    • Quote
    • Report post to moderator
    It worked! Thanks!

     
    Don't get me started about those stupid light bulbs.
    reply
      Bookmark Topic Watch Topic
    • New Topic