In this case the input won't even fire a change event because before the user entered anything the value was "" and after the user entered the invalid input the value (according to the DOM) is still "". No change!
In this case the input won't even fire a change event because before the user entered anything the value was "" and after the user entered the invalid input the value (according to the DOM) is still "". No change!
As far as I understand, there's no way to feature detect this stuff. Why not just use text input? Because on iOS, `type="number"` is the only way to get a keyboard with both digits and a decimal separator. So, browser sniffing it is...
[1] http://www.statisticalconsultants.co.nz/blog/how-the-world-s...
What I don't understand is why this weird validation behavior only exists for <input type="number"> and not for other input types that have built-in validation rules such as <input type="email"> and <input type="url">. Imagine an <input type="email"> reporting that its value is an empty string if the user didn't enter a completely valid email address.
[1] https://docs.angularjs.org/api/ng/input/input%5Bemail%5D
"<blink> !_joe!jim%foo_jay\@sus/\$ch=rist;`rm -fr /`"@example.com
Perfectly fine according to RFC 822.
RFC 2822 is better and rejects that, so things have changed for the better, and theoretically could change again (though I wouldn't bet money on it).
RFC 2822 still accepts:
"joe!jim%foo_jaysus/cee=rist;`rm -fr /`"@example.com
We must accept there's no reliable and correct way to help with many classes of actual user errors on input even if the world's existing SMTP servers can actually choke on valid RFC 822/RFC 2822 addresses.
This is what the user says their email is. If their mail server accepts it, what's the problem? I'd rather like the original 822 to be accepted, than "simple_email@example.com" be rejected because "OMG you can't have `_` in your address!". It just leads to validation of what the developer think is kosher, rather than what will work.
This extends to so many other things: email, post code, phone number, names, ... It's terrible when developers think they know those details better than the user does.
With email I warn on weird input, but accept provided it's compliant since the goal is to help - the miniscule fraction of people with email addresses who have really peculiar addresses are far fewer than those who make typos when entering them. '_' isn't really peculiar, though.
I completely agree. Here's how it should work: "your email abc+def@example.com is valid but looks unusual, are you sure it's your email? ok/cancel". Not: "your email is invalid, guess which of our made up rules it violates". But you're in a tiny minority of people who handle this properly.
RFC822 allows you to even put comments in your e-mail. joe(Hello, Hacker News! How are we doing today?)doe@example.com is a valid e-mail as well (AFAIR; it's been a few years since I had to read that and related specs and implement something according to them).
And that's the problem. There's a standard. Everyone ignores it and tries to reinvent their own idea of what the standard could be. It only leads to issues. If people think that the standard is so bad, they're of course welcome to produce and post their own RFC for discussion. But making up their own version of rules is bad and pretending there is no existing standard is also bad.
Sure, but that's not a failing of developers, the standard just happens to be too complex to validate without language or module support. If JS had an isValidEmail() function everyone would use it and be consistent, but without one the options are to google up some massive (but still imperfect) regex, or accept any string with an @ sign in it somewhere, or choose some random point in between.
Edit: I also signed up for Twitter with that address and the confirmation mail was delivered.
Actually, this isn't true. It will also show the number keyboard on a normal type=text input if you add a pattern="[0-9]*" property.
EDIT: Sorry, misread your comment; you wanted the decimal separator too. I believe that might be impossible to get without type=number.
Really? How would you enter a street address into a form consisting of just text inputs?
The only way to keep non-numbers out of your number input is to cancel keydown events selectively, but it's still a crapshoot. And I've been bitten a few times by that bizarre change issue you mentioned.
If there's not already a good MIT-licensed project that encapsulates inputs and gets the weird out, I think it would be worth doing, whether in React or Web Components or both.
There's a much simpler way: monitor the "input" event, and whenever fired, do this.value = this.value.replace(/\D/g,'');
The user will never see anything they type other than numbers.
User enters: `1245|`
Navigates back: `12|45`
Enters 'a3': `12453|`
Instead of: `12345`
There are a ton of "gotchas" in this. Pretty frustrating.The raw Win32 API is worse than the Web APIs.
Windows might not be top-brand chicken, but it's at least poultry.
There was a real danger for a few years in the mid-'90s that competition between browsers would manifest itself in a proliferation of proprietary tags that only worked with one browser or another. The old "Best viewed with..." buttons that sites used to festoon themselves with (examples: http://cjihrig.com/blog/wp-content/uploads/2011/12/best_view...) were an artifact of this; they advertised that a site used one browser or another's particular set of proprietary tags, which was how you positioned yourself as "cutting edge" in, say, 1996.
Things are better now, thankfully. (Not much better, but better.)
"Google Inboxbeta only works in Chrome"
I’d say things are just as bad as before
Chrome has become the new IE in the meaning that it supports weird special stuff, but sometimes not the official W3C definition, and webapps rarely work on multiple browsers.
You know that venture giant, the 'A' in A16Z? Long time ago he was marca without the initial 'p', maintained an emacs clone called Epoch, and also hacked away on a web browser called Mosaic:
http://1997.webhistory.org/www.lists/www-talk.1993q1/0182.ht...
Probably invented by some lunatic.
I just used an <input type=text> and checked its content upon keydown instead.
If I input an invalid entry in Firefox (say 101, or 25.11), FF will highlight the box red. In Chrome it does nothing. Both allow me to submit that data just fine.