How to not allow all the Chars in a submit to be Upper case but ONLY allow 1st char t

Hi,

Is there a nifty function that you all know which would allow us to detect and prevent submissions
that have too many Upper case letters in them, which of course is bad because it stands for someone
SHOUTING online set aside that it does not look good, while allowing for 1st Characters of each
sentence to be Upper case which is correct English.

While this function Keeps in mind that in certain languages such as German, other Words beside
the 1st Word of a sentence will be Upper case.

I know this is a real tough nut to crack.

ThanX

You could use Javascript to convert all the text to lowercase.
Or, if you wish to actually ‘detect’ the presence of ALL UPPERCASE and reject the submission, a regular expression could do it for you.

Hi,

As noted it is not that simple.
That is the issue is NOT all upper case, but say 60% upper case, or 50% upper case, or more to exactly
only sentences with 1st letter in upper case are to be allowed.

You know, it’d be easier to let your users write how they want to. Some people write in capitals all the time, because they’re possibly used to it from work etc. But that’s no reason to correct them. Anyway the logic is fairly straight forward:

  1. Create a function to calculate whether or not the percentage of upper case characters in a string exceeds a given percentage (so 2 arguments - returns true if the amount of capitals exceeds your threshold. The simplest method that comes to mind is a case-sensitive preg_match of capital letters ~[A-Z]~ and get the number of results found, compare it to the length of the original string).
  2. If this function returns true, set it all to lower case and then do a search (using preg_replace) to capitalise the first letter after punctuation, newlines and the start of the string.

Maybe something in this google search will be useful

http://www.google.com/search?q=php+proper+case&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:unofficial&client=firefox-a