You can do it rather easily with javascript. Here's some code that should help:
Your form field will respond to the onblur event to reformat and validate the phone number entered.
<input type=text name=phone id=phone onblur="reformatPhone(this);">
Then input some javascript into your page:
<script language=javascript>
function reformatPhone(field)
{
var validPhoneLength = 10;
var strippedValue = stripInvalidChars(field.value, "0123456789");
if(strippedValue.length == validPhoneLength)
{
field.value = strippedValue.substring(0,3) + '-' + strippedValue.substring(3,6) + '-' + strippedValue.substring(6,10);
}
else
{
alert('The phone number entered is not a valid phone number.');
field.focus();
}
}
function stripInvalidChars(strValue, validChars)
{
var retval = "";
var curDigit = "";
for (i=0; i < strValue.length; i++)
{
curDigit = strValue.substring(i,i+1);
if (validChars.indexOf(curDigit) != -1)
{
retval += curDigit;
}
}
return retval;
}
</script>
Hope this gets you started.