Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

removal of spaces for a telephone number

Status
Not open for further replies.

bluesauceuk

Programmer
Jan 1, 2001
73
0
0
GB
In a form I have a form field for a telephone number.

I would like to convert it

from this "07712 123456" to this "447712123456"

As you see I need to remove the spaces and the leading zero and replace the leading zero with 44.

Can anyone help?

 
Sometimes there is not always a space would this effect any of the code?
 
<cfset myNumber = &quot;07712 123456&quot;>
<cfif mid(myNumber, 1, 0) eq &quot;0&quot;>
<cfset myNumber = replace(myNumber, &quot;0&quot;, &quot;44&quot;, &quot;One&quot;)>
</cfif>
<cfset myNumber = replace(myNumber, &quot; &quot;, &quot;&quot;, &quot;All&quot;)>

A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.
- Quote by Douglas Adams
 
Ooops!

The spaces are removed - but the replace of ititial zero has not worked what is wrong

<code>

<cfset myNumber = &quot;07712 123006&quot;>
original string is....'<cfoutput>#mynumber#</cfoutput>' <BR>
<cfset myNumber = replace(myNumber, &quot; &quot;, &quot;&quot;, &quot;All&quot;)>
<cfif mid(myNumber, 1, 0) eq &quot;0&quot;>
<cfset myNumber = replace(myNumber, &quot;0&quot;, &quot;44&quot;, &quot;One&quot;)>
</cfif>
done string is....'<cfoutput>#mynumber#</cfoutput>'

</code>

PS: notice the original number is different to check that that other zeros are not replaced...

Help!


 
Try this:

<cfset MyNumber = Replace(MyNumber,&quot; &quot;,&quot;&quot;,&quot;all&quot;)>
<cfif Left(MyNumber,1) eq 0>
<cfset MyNumber = Right(MyNumber,Len(MyNumber)-1)>
</cfif>

chau
 
Right after hours of trying here is the code that works..

<cfset myNumber = &quot;07811 001122&quot;>
original string is....'<cfoutput>#mynumber#</cfoutput>' <BR>
<cfset MyNumber = Replace(MyNumber,&quot; &quot;,&quot;&quot;,&quot;all&quot;)>
<cfif Left(MyNumber,1) eq 0>
<cfset MyNumber = Right(MyNumber,Len(MyNumber)-1)>
<cfset MyNumber = &quot;44&quot; & MyNumber>
</cfif>
done string is....'<cfoutput>#mynumber#</cfoutput>'

Thanks to all for your help!

Cheers

Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top