• Post Reply Bookmark Topic Watch Topic
  • New Topic

isNaN  RSS feed

 
Daniel Martos
Ranch Hand
Posts: 126
1
  • Mark post as helpful
  • send pies
  • 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?

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37507
551
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
Marshal
Posts: 37507
551
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
    • Quote
    • Report post to moderator
    It worked! Thanks!

     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!