4 ms·
I am seeing a lot of criticism of this library in the comments. Does anyone have better suggestions aside from “just let the user enter ‘fuck you’ for a date an
by IgorPartola 8y ago
I am seeing a lot of criticism of this library in the comments. Does anyone have better suggestions aside from “just let the user enter ‘fuck you’ for a date and ‘screw this’ for their phone number”?
I am currently using Cleave for a project where the customer unequivocally requested this kind of functionality. Specifically I need to implement phone masking, date masking (no calendar pickers except native mobile ones allowed), and number and currency validation and masking. Cleave was the least opinionated library of its kind that I found.
- morpheuskafka 8y agoI don't have direct experience but libphonenumber looks pretty comprehensive: https://github.com/googlei18n/libphonenumber https://github.com/googlei18n/libphonenumber
- mgbmtl 8y agoyep, it's what Cleave.js uses for phone number formatting.
- tcd 8y agoNo JS library will stop that when you can just POST the form directly. Best let the user input as they please and let the server do the rest.
- tokyodude 8y agoI would prefer a generic <input type="text"> or <input="number">. Choose the one that gives me the best input experience on mobile. <input="email"> if it's email for example. I would then prefer some live validation JavaScript that highlights if my input is wrong and tells me what it think is wrong but does not mess with my input. Ideally the JavaScript validation does not warn me in until I leave the field because if say I'm typing a phone number and after 1 digit the field turns red, to me that feels like shouting "Hey IDIOT! ONE DIGIT IS NOT A PHONE NUMBER!" which of course I know I just hadn't finished typing. On top of that I want the form to not be stupid. Let me enter 555-555-5555 or 5555555555 for a phone number. Let me enter 1111222233334444 or 1111 2222 3333 4444 for a CC number. Let me enter 01/19 or 1/19 for an expiration date. Trim whitespace on submission too. Don't force me to jump through hoops the code should be smart enough to deal with. Don't correct this kind of text in the field, correct it on submission. If something is ambiguous then add that to your validation message.
- pault 8y agoDon't format on keypress. Ideally, give the user feedback on their input while they type, and disable saving until the field is correctly formatted. If you must have automated formatting, do it on blur instead.
- Aeolun 8y agoValidate that the content is correct, but never automatically format text. It may be possible, but I have yet to see a perfect implementation.
- ttty 8y agoIf a user is gonna write that and you force him to write a proper number he'll give you a fake one and you'll waste time sending marketing SMS and calls
- laurent123456 8y agoThat's usually how I give my email to access free public wifi: Jvkrhgjrjng@jcifjf.com Invalid email Jvkrhgjrjng@gmail.com Thanks!
- mgbmtl 8y agoI agree, however, if the user did want to enter their phone number and they did not notice a silly error because of how it was entered, then you've lost an opportunity. We are seeing this lib as users who get frustrated with marketing forms. There are other use-cases out there. I work with non-profits, where they may not have the budget for fancier validation, so this helps a lot.
- IgorPartola 8y agoWhat I am working on is not marketing. Users don’t really have the option of fake numbers or skipping forms. Not that I want it to be inconvenient. Far from it.
- mch82 8y agoGitHub has an input-mask topic with quite a few alternatives https://github.com/topics/input-mask https://github.com/topics/input-mask Cleave.js is the top starred option Edit: the #2 library, text-mask, doesn’t seem to have the issues with the date field