ColdFusion Help - Form Vallidation

I have a form that allows the website admin to create a new member in the database. The form collects simple information like a company name, owner and phone numbers, etc. I can get the form to insert all the data fine.

Now I want to format the phone number a specific way. Like say the admin puts in the phone number “(555) 555-5555”. I want CF to take that information and format it to “555.555.5555”, but only if the admin inserts data. If the admin does not put in a number i want CF to leave it blank. Here is the code I have.

<cflock name="InesertNewRecord" type="exclusive" timeout="30">
<cftransaction>
<cfif Trim('form.phone') is "">
<cfexit>
<cfelse>
<cfset cleanPhone = ReReplace(form.phone, "[[:space:]]", "", "ALL")>
<cfset cleanPhone = ReReplace(form.phone, "[[:punct:]]", "", "ALL")>
<cfset cleanPhone = ReReplace(form.phone, "[^0-9]", "", "ALL")>
<cfset areaCode = Left(cleanPhone, 3)>
<cfset firstThree = Mid(cleanPhone, 4,3)>
<cfset lastFour = Right(cleanPhone, 4)>
<cfset finalPhone = areacode&'.'&firstThree&'.'&lastFour>
</cfif>
<cfquery name="AddMember" datasource="#application.DSN#">
	INSERT INTO members (companyname, owner, street, town, zipcode, phone, fax, email, website, cars)
    VALUES ('#form.companyname#', '#form.owner#', '#form.street#', '#form.town#', '#form.zipcode#', '#finalPhone#', '#form.fax#', '#form.email#', '#form.website#', '#form.cars#')
</cfquery>

Right now, if the admin enters in a phone number it edits it perfectly, but if the admin leaves it blank, CF inserts … as the phone number. Can anyone help?

-Matt :ko: