[thelist] js validating numbers

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


Hello,

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
work:

========================================
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?

Tom

=====
var me = tom.pixelmech.webDeveloper();

http://www.pixelmech.com/
http://www.maccaws.com/
[Making A Commercial Case for Adopting Web Standards]

__________________________________________________
Do you Yahoo!?
Yahoo! Shopping - Send Flowers for Valentine's Day
http://shopping.yahoo.com



More information about the thelist mailing list