Giter VIP home page Giter VIP logo

Comments (7)

jackocnr avatar jackocnr commented on August 15, 2024

Thanks for raising this. I'd appreciate your thoughts on the subject: can you describe the reason(s) why you think someone might type a letter in the input in the first place (is it just by accident or are there other possible reasons?)? And why you think silently ignoring the user's action would be better than allowing it and then if they've typed the equivalent of a valid number (like in your example) then converting the letters to numbers, else failing validation?

from intl-tel-input.

adamhinckley avatar adamhinckley commented on August 15, 2024

Thanks for the reply.

I don't know why someone would intentionally type a letter in a phone input in my case, but I can see it happening by accident then being seen as valid when it's not the number the user intended to enter. I also see why it could be desired in some cases outside of my own.

Rather than silently ignoring the letter, I think it would be ideal for it to be seen as invalid so I can show an error to the user. Is this something that could be added as a boolean to the config?

Or Is there a way to extract the string, as typed by the user, so I can run my own validation on it because getNumber() returns the value with the letters replaced with numbers? If that can be done I can check for the existence of letters on my own.

from intl-tel-input.

adamhinckley avatar adamhinckley commented on August 15, 2024

We ended up finding a work around.

Context: this is in a React app and we used the React component from this library (thank you 🙏) as a guide to build our own React component.

This is how we are able to get the input as the user typed and check for letters

// remove non-english letters and accents
const rawValue = inputEl.value.normalize('NFD').replace(/[\u0300-\u036f]/g, '');

const isValid = itiRef.current.isValidNumberPrecise() && !/[A-Za-z]/.test(rawValue);

from intl-tel-input.

jackocnr avatar jackocnr commented on August 15, 2024

Rather than silently ignoring the letter, I think it would be ideal for it to be seen as invalid so I can show an error to the user

Thanks for your input. I agree with this. I think we should add an extra condition to isValidNumber and isValidNumberPrecise to confirm there are no alpha chars in there. We use libphonenumber for validation and I think they support alpha char substitutions because in some cases that is useful to them e.g. for when users want to dial numbers in that way, but I don't think it would ever be useful for this plugin. I'll re-open this issue to track this feature. I would be open to a pull request that adds this extra check in those two methods.

from intl-tel-input.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.