jackocnr / intl-tel-input

A JavaScript plugin for entering and validating international telephone numbers. React and Vue components also included.
https://intl-tel-input.com
MIT License
7.69k stars 1.95k forks source link

Incorrect validation of phone number containing letters #1823

Closed badikgit closed 1 month ago

badikgit commented 2 months ago

Plugin version

e.g. v24.5.0 (please try latest version)

Steps to reproduce

  1. Create an iti instance as in the documentation examples with the settings provided in Initialisation options (below).
  2. Enter a phone number containing letters in the input, for example +1-888-library
  3. Get the number and check the validation of the number.

Expected behaviour

Calling isValidNumber is expected to return true, as it was in previous versions (e.g. v18.2.1).

Actual behaviour

The result of calling getValidationError is 0, which corresponds to the possible number. The result of calling getNumber is also correct, and the phone number containing letters is converted to a valid phone number with digits instead of letters. But despite all this, the result of calling isValidNumber is false.

{
    getNumber:  "+18885427279",
    getValidationError: 0,
    isValidNumber: false,
    isValidNumberPrecise: false,
}

Initialisation options

{
    autoInsertDialCode: true,
    formatAsYouType: true,
    initialCountry: "us",
    nationalMode: false,
    placeholderNumberType: "MOBILE",
    separateDialCode: true,
    utilsScript: "https://cdn.jsdelivr.net/npm/intl-tel-input@24.5.0/build/js/utils.js",
    validationNumberType: "MOBILE",    
}
jackocnr commented 1 month ago

Can you explain your use case - why you want to support users replacing digits with letters? I see you have validationNumberType set to MOBILE, so in your case, you're only accepting mobile numbers - I can't imagine why someone would replace digits with letters in their mobile number, can you? In my opinion, if you're asking for a mobile number and the user includes a letter character, it would be much more likely to be a mistake than intentional.

jackocnr commented 1 month ago

You mention that in previous versions, the plugin used to return valid for (valid) numbers containing letters, and you're right, but so many people complained, saying validation is passing when it shouldn't, that I changed it so that validation fails if there are any letters, and I haven't had any complaints since.

(this change was made in v20.0.0 by the way, back in March of this year)

badikgit commented 1 month ago

You are right, this is a rare use case when it may be more convenient for the user to enter the number using letters. It is only relevant for people (like VIP) who specifically buy a number that is convenient to enter as a word. I was just confused when I saw the validation problem with this use case in the new version, unlike the last version I used, and I considered this a unique and attractive feature.

jackocnr commented 1 month ago

Ok I'll close this issue for now.

jackocnr commented 1 month ago

You may want to review the breaking changes in the release notes of each major version since the one you were using before, to avoid surprises like this.

badikgit commented 1 month ago

Thank you for the helpful advice.