PDA

View Full Version : Mobile phone number formatting...



stamper
12-Mar-2007, 02:33 AM
Hi...

I am fairly sure this is going to be a computational related question. So, here goes.

On my form, I collect a mobile phone number. As it is used for automatically SMS'ing the person, it has to be in the format of +61419555555. ie Country code, No leading "0" and then the number.

I have a drop list to select the country, which adds the +61 etc and a field to collect the phone number.

The problem is, if the person fills out the phone number with the leading "0" or uses spaces, dashes, brackets etc in the phone number, then the SMS will not be sent.

In most countries, mobile phone numbers start with a "0", but, not in North America.

So, what I need to do is:

1. take out the leading "0" IF it is exists
2. strip out any non numerical characters
3. derive the country code and the mobile phone number

Using a formatting condition wont really work, as I dont wont people filling in the number, and then ending up at an error page saying that they need to re-enter the number in the correct format.

SO, there you have it. Hope this all makes sense.

Elso
12-Mar-2007, 01:15 PM
Hi Stamper

Russell may have a better approach, but I will post some ideas I might consider.

Stripping out leading and trailing spaces and leading zeros can be done with your derive_fields like so:

<input type="hidden" name="derive_fields" value="
nMobilePhone1=%rtrim(nMobilePhone1)%,nMobilePhone1=%ltrim0(nMobilePhone1)%,
">

I personally don't know of a means to remove non number characters from a string (I think I tried this question in an earlier post (http://www.tectite.com/vbforums/showthread.php?t=1557)), so as an alternative, I might break the number field up into common sections/fields to lure the user to entering only numbers. I am not sure how mobile phone numbers are broken down, but a normal land line would be
(XXX) XXX-XXXX in which case I might break this up into 3 separate fields and maybe place the formating characters as static text in the appropriate spaces between the fields. Then use the above "ltrim0" to remove any leading zeros and spaces from the first field. I believe the "trim" function works like this:
trim(FieldName) will trim whitespace from both ends of a string.
ltrim(FieldName) will trim whitespace from the left only.
rtrim(fieldName) will trim whitespace from right end only.
ltrim0(FieldName) will trim whitespace and 0 from the left.

Following this logic I might think you can trim any characters you want from either end of a sting. Whether you can trim multiple characters with a single trim function or not, I don't know.

As far as trimming inside I don't believe this is possible. With this limitation you can add in a condition field like so:

<input type="hidden" name="conditions1" value=":@
@TEST@ nMobilePhone1 ~ /^ *[0-9]+ *$/ @You can only enter numbers, no dashes or other charactors.@:'>
Run this test on each of your number fields.

You might run this conditional test first and then strip out spaces and zeros as needed.

Hope this helps and maybe Russell can confirm any of my assumptions here.
Elso

russellr
12-Mar-2007, 09:55 PM
Hi,

There's currently no way to strip out non-numeric characters from a field.

The logic behind this is that there's almost no situation where that makes sense.

However, I think you've presented a case where it might make sense.


+61(2)9123-4567

becomes: 61291234567

I guess credit card details is another case:


4564-1234-5678-9012
4564 1234 5678 9012

Personally, I prefer the user reads the instructions and enters the phone number the way they should. If they make a mistake, they get an error page and then return to the form with the data intact - they then need to correct their mistake.

This approach helps protect from spammer activity too.

I also like Nelson's idea of grouping the digits into separate fields and testing each one.

Having said that, we are putting string manipulation features into a future vesion, so you will be able to do things like this if you really want to.