Trim out leading zero in phone number in form

Hi,

Is there a way to remove the leading zero in a phone number when submitting a simple form? The form has a server connect to mailer to send out an email and I need to include the POST value of the phone number without a leading zero, like mobile number from ‘0400200300’ to submit as ‘400200300’

Hi.

There is no direct formatter to do this in Wappler from what I know.
An elaborate method would be to do a substring (0,1) to get the first character, check if its a 0, and if it is, substring the value again from (1, length-of-value - 1).

Or, you can write your own custom TRIM formatter which accepts a param for which character to trim.

If you know the numbers are as in your example - ie with no spaces - I think you could just use .toNumber() to remove the leading zero. To remove spaces, as well as the leading zero, you could use the replace formatter, eg: phoneNumber.value.replace(' ', '').toNumber().

@sid’s approach would allow spaces to be preserved.

Thanks @sid. @TomD, how do I get formatter to work on a simple contact form (non database) that connects to server content to send an email?

You just apply the formatter on the server side in your server action, where you bind the value.

Thanks @Teodor, I can’t see formatter on the server side. I’ve never used formatter.

Click the edit icon and the editor will appear. There you can format your data.

@Teodor I have and I don’t see a formatter option?


Click the magic wand icon displayed in the data picker dialog, seen on your second screenshot.

@Teodor, clicking on the magic wand brings up another window, no formatting options.


and if I click again on the lightening bolt, the same original window comes up, without formatter?

Clicking the magic wand icon brings up exactly the formatter as shown on your screenshot … right click your value and select the formatting option you need.

@Teodor, great! Now I can see the formatter options. Which one would remove the leading zero in the phone number?
click5

@Teodor, yes you are correct! I got it to work!!! Thanks you very much!
Also thanks @TomD and @sid!!~
@TomD your suggestion work!

1 Like

Glad you got it working.

Just a suggestion: You should mark the post which has the actual solution to help others viewing the post in the future. In this case, Paul’s.

1 Like