3 ms·
In case anyone asks you to implement any input formatting, see if you can get them to change their minds. IMO the most bug-prone and useless feature of websites
by hallway_monitor 5y ago
In case anyone asks you to implement any input formatting, see if you can get them to change their minds. IMO the most bug-prone and useless feature of websites. Let the user put in whatever they want and just input.replace(/[^0-9]+/, ''). You, your users and your product owners will be happier.
- Dunedan 5y agoThis doesn't work for phone numbers if you want to do something programmatically with them. In Germany it's for example common to include the international prefix _and_ a trunk prefix like this in written phone numbers: +49 (0)30 23125 123 Your naive approach to just replace non-number characters would lead to an invalid number in such a case. Using libphonenumber you'd get a correctly normalized phone number while the user doesn't get bothered for inputting a technically invalid number: https://libphonenumber.appspot.com/phonenumberparser?number=%2B49+%280%2930+23125+123 https://libphonenumber.appspot.com/phonenumberparser?number=...