jacmaes Posted February 25, 2016 Share Posted February 25, 2016 How do you guys deal with editors (or regular users via front-end form submissions) who have their CAPS LOCK key enabled and merrily type in entire paragraphs in uppercase letters as if there's no tomorrow? I don't know why people do this, this drives me crazy Do you detect it on the front end with JS and throw a warning, or "process it in post-production" with something like ucwords(strtolower($foo))? I thought that some simple instructions at the start of the form would be enough, but there's always someone who doesn't read them or just doesn't care. Link to comment Share on other sites More sharing options...
dragan Posted February 25, 2016 Share Posted February 25, 2016 Depends a bit on the actual use-case / scenario. If it's a typical article comments feature, I'd say have an admin review the comments before publishing. A JS or PHP solution is probably not going to work in 100% of all cases - if someone lists capitalized terms / company names like IBM, HTML, BMW or some such - that's not necessarily shouting or spam, but valid input. ucwords() would certainly not be the perfect cure; I only ever use it for (english language) titles. For german or french, that would be useless even for titles / headings, because it's not formatted like in english... If that's a real problem, I'd probably look into some regex magic and block form submission, if >x% of the entire text is uppercase, but I'm by no means a regex guru Perhaps something simple as that might help: var str = "OH HAI. HOW ARE YOU TODAY? WOULD YOU LIKE SOME cheese with THAT?", uc = str.replace(/[^A-Z]/g, "").length, total = str.length; if(uc > (total/20)) { console.log("HEY COWBOY! WE'RE NOT IN KANSAS ANYMORE!"); // form submit false etc. } 1 Link to comment Share on other sites More sharing options...
diogo Posted February 25, 2016 Share Posted February 25, 2016 If that's a real problem, I'd probably look into some regex magic and block form submission, if >x% of the entire text is uppercase, but I'm by no means a regex guru You don't need regex. You can test simply by converting the string to uppercase and then compare it with the original string: if (strtoupper($str) === $str) EDIT: Or in Js if (string.toUpperCase() === string) 1 Link to comment Share on other sites More sharing options...
Recommended Posts