Stripping dashes from phone input

Hi there!

How can I strip out dashes (or any symbols) from a phone number as the input is inserted into the database?

I have a text input where people can input their phone number.
Because I want them to easily type whatever they’re used to typing, there is a regex formula on it already: ^\D?(\d{3})\D?\D?(\d{3})\D?(\d{4})$
This way people can put in:
5555555555
555-555-5555
555.555.5555
(Basically, any combo of 3 number, symbol or not, 3 numbers, symbol or not, four numbers.)

Then I check the database and see whether it’s there or not, and based on that either log them in with a password or pass them to a sign-up page.

But, I’d like the number to formatted to only 10 numbers as I put it into the database so it’s consistent.
But, seems like server side action rules don’t format it for insert?

I do copy the input they made into a hidden field on another form so they can type in their other sign-up data there. But, I can’t seem to figure out how to alter their input to strip the dashes. I can only get warnings to pop up if it doesn’t fit the format.

Thanks!!
Jeff

There are probably a number of ways you could do this. If you just have to replace dots and dashes, and one or two other non-numeric characters, you could just use the slugify formatter on the value before inserting it.

1 Like

That seems to work.
THANKS!!!

It could theoretically be any symbol not just dashes and dots.

Or use the replace function on a hidden second input field that has the dynamic value set to the first visible input field.

.replace('-', '')
2 Likes

In which case @max_gb’s approach would be a good solution. You could use:
dmx-bind:value="text1.value.replace(/\D/g,'')"
… for the hidden input - to strip out any non-numeric characters. Unfortunately I don’t think this is possible in server connect as regex isn’t available.

1 Like

I know this is an old thread but I found it cause I was looking for the Wappler way to strip non-numeric characters but ended up writing a quick extension to do it.

Thought I’d post it here for anyone else looking at this thread.extensions.zip (5.8 KB)

3 Likes