home

Quickies, by Andrea Olivato

text

Find if a var is numeric in #javscript

How to be sure a variable is numeric with #js

function IsNumeric(sText) {
	var ValidChars = "0123456789.";
	var IsNumber=true;
	var Char;	 

	for ( i = 0; i < sText.length && IsNumber == true; i++) { 
		Char = sText.charAt(i); 
		if (ValidChars.indexOf(Char) == -1)
			IsNumber = false;
	}
	return IsNumber;

}

2 years ago

May 27, 2009
Comments (View)
blog comments powered by Disqus