[thelist] js validating numbers

Tom Dell'Aringa pixelmech at yahoo.com
Tue Feb 11 08:27:11 CST 2003


I am working on a form where I have to validate some fields to make
sure the values entered are numeric. I have this function which does

function IsNumeric(strString)
	var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;

	//  test strString consists of valid characters listed above
	for (i = 0; i < strString.length && blnResult == true; i++)
		strChar = strString.charAt(i);
		if (strValidChars.indexOf(strChar) == -1)
			blnResult = false;
	return blnResult;

However, it looks like they want me to validate 2 types of numbers: 1
- that its a number, and 2 - that its a *percent* (i.e., 5.76) or
floating point. I'm not sure my function is sufficient for this
second part..what do you think? Should they be forced to enter 2.00
for 2%? How would I manage forcing a percentage?


var me = tom.pixelmech.webDeveloper();

[Making A Commercial Case for Adopting Web Standards]

Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day

More information about the thelist mailing list