Solved

decimal Validation

Posted on 2005-03-22
Medium Priority
1,045 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

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

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses
Course of the Month12 days, 1 hour left to enroll