I'm currently working on a javascript form validator and have run into a problem. The validator is used to make sure that the customer has entered a number in the quantity input box of the item they wish to purchase.
function validateRE(fieldToCheck, strRegExp, msg, min, max) {
	if (!min) { min = 0 }
	if (!max) { max = 100 }
	for (i=0;i<15;i++)
		if (fieldToCheck[i].value) {
			var re_pattern = strRegExp;
			if (!re_pattern.test(fieldToCheck[i].value) || fieldToCheck[i].value.length < min || fieldToCheck[i].value.length > max) {
			  	return false;
	return true;
Used with:
<form method="post" action="../some_URL"
   onsubmit="return (
   validateRE(this.quantity, /^[1-9]{1}$|^[0-9]{2,3}$/,
      'Please enter a Quantity.', 1, 3)  
The part in question is the red highlighted section.
The number of items that is under a specific product is generated dynamically and can range from 2-20. How can I get javascript to count the total number of items and run "for i=0;i<total number" instead so it is different for each product page?