Solved

# decimal Validation

Posted on 2005-03-22
Medium Priority
1,048 Views
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
Question by:Docjayman

LVL 3

Accepted Solution

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

ID: 13608506
Outstanding, it worked perfect!
0

## Featured Post

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
Course of the Month8 days, 19 hours left to enroll