• Post Reply Bookmark Topic Watch Topic
  • New Topic

Validate Numer only in Textbox  RSS feed

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am Using Java Script to validate only phone in text box using following code ...
if(isNaN(parseInt(document.frm.phone.value)))
{
alert("Enetr Number only in the Phone Column");
}
if i give the input any character (example: abcdef ) in texbox it will check and give the Correct alert message ...
but i give the input (example: 52hghg ) in textbox it will accept it .. Whenever i give the input starting with any number it will accept ..
Why? What is the Reason How to Validate number only in textbox...
 
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't call the parseInt method. Instead use


When the input is something like '52hghg', the parseInt method parses it into an integer (52 in this example). So the isNaN() method will not return a true.
 
Mani Ram
Ranch Hand
Posts: 1140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And one more thing: Next time you have a question on JavaScript (or HTML) post it in HTML and JavaScript forum.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!