SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    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

    Anoox search engine volunteer

    www.anoox.com

  2. #2
    Avid Logophile silver trophy
    ParkinT's Avatar
    Join Date
    May 2006
    Location
    Central Florida
    Posts
    2,329
    Mentioned
    191 Post(s)
    Tagged
    4 Thread(s)
    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.
    Don't be yourself. Be someone a little nicer. -Mignon McLaughlin, journalist and author (1913-1983)


    Git is for EVERYONE
    Literally, the best app for readers.
    Make Your P@ssw0rd Secure
    Leveraging SubDomains

  3. #3
    SitePoint Wizard WorldNews's Avatar
    Join Date
    Nov 2007
    Posts
    1,033
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    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.

    Quote Originally Posted by ParkinT View Post
    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.

    Anoox search engine volunteer

    www.anoox.com

  4. #4
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  5. #5
    SitePoint Addict
    Join Date
    Apr 2009
    Posts
    357
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Maybe something in this google search will be useful

    http://www.google.com/search?q=php+p...ient=firefox-a
    Doug G
    =====
    "If you ain't the lead dog, the view is always the same - Anon


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •