﻿// 8-24-2006 : Kendall Beaman
// Function replaces all consecutive dashes with a single dash for a given form element
// frm is the form element you wish to process. Here's an example of how to call this function
// <form id="testForm" action="" method="post" onsubmit="filterDashes(getElementById('testForm'));">
// I recommend using the id attribute rather than name as name is deprecated and use the getElementById function.
// Could also use ' onsubmit="filterDashes(this);" which will work just fine

function filterDashes( frm )
{
	var str;
	
	var result;
	
	for (x=0; x < frm.elements.length; x++)
	{
		var pattern = /-{2,}/g
		str = frm.elements[x].value;
		
		if ( pattern.test(str) == true)
		{
						
			frm.elements[x].value = str.replace(pattern,"-");
		}
	}
}

// Function searches the entire document for forms and then goes through them to remove dashes
// Not sure if this is needed but it's here in case anyone wants to use it.

function allFilterDashes ( )
{
	var forms = document.getElementsByTagName("form");
	
	for ( var x = 0; x < forms.length; x++ )
		filterDashes(forms[x]);
}

