WelcomeServicesPortfolioKnowledge BaseContact Us
27 Seconds, Inc.


Knowledge base View Article

need hosting?

Need hosting? We use and love our host - CrystalTech.com!
Need hosting? We use and love our host - CrystalTech.com!

Text Disguise - CAPTCHA-image/Human Interactive Proof web services

National Holiday Dates and Bank Holiday Dates - web site that provides the dates of national and bank holidays for the United States, United Kingdom, Ireland and Scotland

Holiday Web Service - web services for programmers to provide the dates of national and bank holidays in their applications for the United States, United Kingdom, Ireland and Scotland

Our Family Heart - web site to help families communicate no matter where they are

What?! You haven't heard about the greatest remote controlled flyer to come out in years?! Checkout the FlyTech DragonFly now!

JavaScript IsNumeric()

Summary: Function that does the exact same as VBScript's IsNumeric.
 
Keywords: ISNUMERIC
NUMBER
Applicable Software: JavaScript
 
Body:

function isNumeric(vTestValue)
{
	// put the TEST value into a string object variable
	var sField = new String(Trim(vTestValue));
	
	// check for a length of 0 - if so, return false
	if(sField.length==0) { return false; }
	else if(sField.length==1 && (sField.charAt(0) == '.' || sField.charAt(0) == ',' || (sField.charAt(0) == '-'))) { return false; }
	
	// loop through each character of the string
	for(var x=0; x < sField.length; x++) {
		// if the character is < 0 or > 9, return false (not a number)
		if((sField.charAt(x) >= '0' && sField.charAt(x) <= '9') || sField.charAt(x) == '.' || sField.charAt(x) == ',' || (sField.charAt(x) == '-' && x==0)) { /* do nothing */ }
		else { return false; }
	}
	
	// made it through the loop - we have a number
	return true;
}

Update, 3/22/2002: Dave Clayton of CCS Tech Group found a bug in the code. The code above has been fixed. Thanks Dave! You win a cookie!

 
Author: Douglas L. Setzer, II, http://www.27seconds.com
Posted On: 3/5/2002 11:57:23 AM

Rate this article: Average: 4.4
n/a12345678910
Comments?

Article Search   |   All Articles

 

 
©2002 27 Seconds, Inc. All Rights Reserved.