?
Solved

decimal Validation

Posted on 2005-03-22
2
Medium Priority
?
1,048 Views
Last Modified: 2010-08-05
I just want to make sure that a number is being enter into the form including a decimal. Does the isNaN cover decimals?  

Can I get a validation to check for this?

Thanks

0
Comment
Question by:Docjayman
2 Comments
 
LVL 3

Accepted Solution

by:
mixart earned 2000 total points
ID: 13608380
You could check for a period being present like this...


function checkDec(thisnum){
  thisnum = thisnum.toString();
  var numArray = thisnum.split(".");
  //trace("na:"+numArray);
  if(numArray[1]==undefined){
        trace ("no dec");
  } else {
        trace ("has dec");  
  }
}

numtocheck=100.45;
checkDec(numtocheck);

You could also do a test to make sure there are X number of integers after the decimial with


function checkDec(thisnum){
  thisnum = thisnum.toString();
  var numArray = thisnum.split(".");
  //trace("na:"+numArray);
  if(numArray[1]==undefined){
        trace ("no dec");
  } else {
        trace ("has dec");
        trace ("has "+numArray[1].length +" numbers after decimal")
  }
}

numtocheck=100.45;
checkDec(numtocheck);

0
 

Author Comment

by:Docjayman
ID: 13608506
Outstanding, it worked perfect!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
There are times in your Flash CS4 application when you want more than a simple pointer or a hand, and it's hard to find an ideal walk-through to tell you what to do.  I spent a few days recently learning my way around making custom cursors in Flash,…
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question