News for hackers. Stuff that matters.
Re:Gmail password first character is case insensitive on mob... by kevincox on Saturday October 09, 2021 @07:31AM (#28808938)
Yup. My role of accepting phone numbers is `input.replace(/[^0-9+]/g, "")`. It might strip some expected information in rare cases but good enough for me.

This works for a lot of other things that people format wildly like Canadian postal codes (which are A1A 1A1 format but many places require presence or absence of a space), credit cards (strip the spaces) and so many other fields.

Re:Gmail password first character is case insensitive on mob... by Aachen on Saturday October 09, 2021 @08:25AM (#28809254)
Why not simply leave it as the user input the value? Validation is one thing, but silently dropping information cannot possibly be helpful for the person that then has to call this number.

I agree it should work for any phone number I've ever encountered, but just why

Re:Gmail password first character is case insensitive on mob... by jodrellblank on Saturday October 09, 2021 @10:11AM (#28809998)
Will it work for the convention in the UK of writing +44 (0)1234 567 8901 which says to use 01234 dialling code inside the UK or 441234 if calling from another country, and don’t dial 4401234 ever?
Re:Gmail password first character is case insensitive on mob... by jacurtis on Saturday October 09, 2021 @02:04PM (#28811902)
A truly global phone number regex is quite literally impossible to make. There are too many combinations and expectations built into these conventions. You listed several here.

The "best" solution is to separate country code into a different field or input. Then have everything other than the country code (generally called a "subscriber number") added to another input.

Then on the backend you would essentially strip out all the non-numeric characters from the subscriber number and combine the country code and stripped "subscriber number" into an E.164 format number and store that in the database.

(Source) I have spent a decade dealing with phone numbers in databases and web forms. This is the "best" way to handle it, and even it isn't bulletproof, but it works 99.8% of the time. The best way to handle the other 0.2% of cases is to make a descriptive error message that explains to the user how you are expecting them to input their number (ie. No extensions, etc).

Here is the E.164 standard: https://www.itu.int/rec/T-REC-E.164/

Re:Gmail password first character is case insensitive on mob... by lelandfe on Saturday October 09, 2021 @10:37AM (#28810241)
This is one of the reasons why I generally don't like `maxlength` on telephone input fields: browsers will truncate pasted-in phone numbers with nary a peep to the user as to why.

Validation with onblur or submission is great, but changing my input makes me angry.

Re:Gmail password first character is case insensitive on mob... by listenallyall on Saturday October 09, 2021 @08:25AM (#28809257)
Using letters in a phone number as a mnemonic, or just to flow better, is not a "rare case." You should revise your regex to accept letters, then whether you store them internally as letters or convert to the corresponding numbers is up to you.
Re:Gmail password first character is case insensitive on mob... by kevincox on Saturday October 09, 2021 @08:34AM (#28809307)
That makes sense if you are making a contact book or social profile. I was focusing on the case where I want the number as contact information. I want to validate up front that it is a number that I can actually call and don't really care about how the user wants to format it.
Re:Gmail password first character is case insensitive on mob... by listenallyall on Saturday October 09, 2021 @11:39AM (#28810788)
Right, but it's user-hostile. I prefer thinking of, and typing, my phone number as a mix of numbers and letters... so why won't you allow me to do so?
Re:Gmail password first character is case insensitive on mob... by kevincox on Saturday October 09, 2021 @11:42AM (#28810811)
I am letting you. It is just when the number is sent to the backend it is converted into a usable format where I can for example generate tel: links and otherwise use the number. I agree that there is some value to being able to each your number back how you typed it, but I'm not sure it is more valuable then showing you the number how I am actually going to try to call it.
Re:Gmail password first character is case insensitive on mob... by listenallyall on Saturday October 09, 2021 @12:03PM (#28810970)
Isn't that exactly what I stated in my initial comment? Not sure why you were so quick to disagree
Re:Gmail password first character is case insensitive on mob... by kevincox on Saturday October 09, 2021 @12:08PM (#28811006)
Sorry, sounds like a misunderstanding. I always meant to accept anything, that is why I put a replace in my top comment not saying that I would reject the form.