﻿//Adds dashes to a Phone field if the field is in correct format
function FormatPhone(ctrl)
{
	var val = ctrl.value;
	
	var replaceExpr = /\W/g	
	val = val.replace(replaceExpr,'');
	replaceExpr = /_/g
	val = val.replace(replaceExpr,'');	
	
	var phone = '';
	if(val.length > 3)
	{
		phone = val.substr(0,3) + '-';
	}
	if(val.length > 6)
	{
		phone += val.substr(3,3)+ '-'+val.substr(6);
	}
	else
	{
		phone += val.substr(3);
	}
	if(phone.length > 1)
	{
		ctrl.value = phone;
	}
	

}
