Comments (7)
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.
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.
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.
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)
- Initialization options: "i18n.countryListAriaLabel" has no effect HOT 2
- Search field not appearing within drop down HOT 4
- Uncaught Error: No country data for 'undefined HOT 23
- Send Country data to Hubspot HOT 1
- Not the correct mask for the country France HOT 2
- Showing invalid number even if the number is valid HOT 9
- initialCountry does not work if you send the country code in the upper register HOT 3
- Issue with setNumber() HOT 2
- Please make esbuild a devDependency again HOT 2
- Validation of empty phone field (mandatory phone input * ) HOT 1
- isValidNumber() passing on invalid number HOT 14
- Accessibility: Dropdown not reading country options HOT 3
- Valid Turkey number starting with some prefixes etc.0561 returns invalid number HOT 3
- Wrong validation with letters HOT 2
- Decrease npm package size HOT 1
- Change placeholder in country search input HOT 1
- JSON import for localization HOT 1
- I'm create IntlTelInput react component using with headless Dialog (Modal) but IntlTelInput can't closing when click outside. HOT 4
- Issue for the phone valid in react component HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from intl-tel-input.