I would like to use a MaskedTextBox for international phone numbers

1 Answer 339 Views
MaskedTextBox
Andre
Top achievements
Rank 1
Andre asked on 11 Apr 2023, 02:35 PM

I would like an editing  mask for phone numbers, along the lines of
"+00 0000 000000" or "+00-0000-000000".

The leading + to be stored as part of the data, but the spaces or hyphens are not.

The only characters that should be typed are digits.

There is unfortunate a variation in how different countries display numbers.

1 Answer, 1 is accepted

Sort by
1
Accepted
Nikolay
Telerik team
answered on 14 Apr 2023, 10:15 AM

Hello Andre,

You can set the desired mask and then remove the spaces with regex:

    $("#phone_number").kendoMaskedTextBox({
          label: "Phone number:",
          mask: "+00 0000 000000",
          unmaskOnPost: true,
          change: function(e) {
            var value = e.sender.value().replace(/\s+/g, '')
            console.log(value)
          }
        });

Dojo demo: https://dojo.telerik.com/EHevuzoj

I hope this is what you are looking for.

Regards,
Nikolay
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Andre
Top achievements
Rank 1
commented on 14 Apr 2023, 10:20 AM

Thanks, I'm actually passing the result through a parser now to rationalize the end result.
Tags
MaskedTextBox
Asked by
Andre
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or