Avoid All Capital Letters in Guestbook

Discussion in 'Javascript' started by Keith Bowes, Jan 6, 2004.

  1. Keith Bowes

    Keith Bowes Guest

    Carlos Marangon wrote:
    >
    > People go to sign my guestbook and wrote all text in capital letters.
    > Did you know any script that shows an window alert when one types the
    > second capital letter?
    >


    It shouldn't be that hard. Keep a global boolean variable that switches
    to true on upper case and false otherwise (hint: bool_var = object.value
    == object.value.toUpperCase()). If it's already true, then show a
    warning. However, it would be better to check it all on submission (to
    allow for initialisms, acronyms, emphasis, etc).

    As usual, use JS for convenience only. Redundant checking must be
    performed on the server side, if possible.
    Keith Bowes, Jan 6, 2004
    #1
    1. Advertising

  2. Hello!


    People go to sign my guestbook and wrote all text in capital letters.
    Did you know any script that shows an window alert when one types the
    second capital letter?


    Best regards,

    Carlos
    Carlos Marangon, Jan 6, 2004
    #2
    1. Advertising

  3. Keith Bowes

    McKirahan Guest

    "Carlos Marangon" <> wrote in message
    news:...
    > Hello!
    >
    >
    > People go to sign my guestbook and wrote all text in capital letters.
    > Did you know any script that shows an window alert when one types the
    > second capital letter?
    >
    >
    > Best regards,
    >
    > Carlos



    Perhaps?


    <html>
    <head>
    <title>capitals.htm</title>
    <script language="javascript" type="text/javascript">
    <!--
    function capitals(that) {
    var Max = that.value.length;
    if (Max < 2) return;
    var Cap = 0;
    for (var i=0; i<that.value.length; i++) {
    var char = that.value.charAt(i);
    if (char >= "A" && char <= "Z") {
    Cap++;
    if (Cap > 1) break;
    } else {
    Cap = 0;
    }
    }
    if (Cap > 1) alert("Two consecutive capital letters!");
    }
    // -->
    </script>
    </head>
    <body>
    <form>
    <input type="text" name="Name" value="" onkeyup="capitals(this)">
    </form>
    </body>
    </html>
    McKirahan, Jan 6, 2004
    #3
  4. Keith Bowes

    McKirahan Guest

    This version only warns the user when "two consecutive capital letters" are
    entered but allows them to continue entering characters. In some cases,
    "two consecutive capital letters" may be allowed.

    <html>
    <head>
    <title>capitalz.htm</title>
    <script language="javascript" type="text/javascript">
    <!--
    function capitals(that) {
    var Cap = false;
    var Max = that.value.length;
    if (Max > 1) {
    for (var i=0; i<Max; i++) {
    var char = that.value.charAt(i);
    if (char >= "A" && char <= "Z") {
    if (Cap) {
    if (i == Max-1) {
    alert("Two consecutive capital letters!");
    return;
    }
    }
    Cap = true;
    } else {
    Cap = false;
    }
    }
    }
    }
    // -->
    </script>
    </head>
    <body>
    <form>
    <input type="text" name="Name" value="" onkeyup="capitals(this)">
    </form>
    </body>
    </html>
    McKirahan, Jan 6, 2004
    #4
  5. McKirahan wrote:

    > [...]
    > if (Cap > 1) alert("Two consecutive capital letters!");


    And what about acronyms?

    The proper way to prevent people from writing only in uppercase
    is a RegExp instead of an iterating function. For example:

    if (/^([A-Z]{10,}[] -@^-`\{-~[]*)+$/.test(sInput))
    {
    alert("Don't CRY, baby! ;-)");
    }

    This matches uppercased text longer than nine letters [1],
    optionally followed by any number of spaces and punctuation
    characters.

    But keep in mind that you can never solve problems on layer 9 technically.


    PointedEars
    ___________
    [1] AFAIK there are no (partially) acronyms longer than
    that besides ROTFLBTCDICAJTTWADBSISWTRHITSBKABAYB :)
    Thomas 'PointedEars' Lahn, Jan 15, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ebi
    Replies:
    2
    Views:
    12,616
    puzzlecracker
    Feb 5, 2005
  2. Eric Wertman
    Replies:
    2
    Views:
    326
  3. Miguel Orrego

    Capital Letters

    Miguel Orrego, Aug 19, 2003, in forum: ASP General
    Replies:
    6
    Views:
    235
    Dave Anderson
    Aug 20, 2003
  4. Ralph Shnelvar

    Splitting on capital letters

    Ralph Shnelvar, Dec 8, 2010, in forum: Ruby
    Replies:
    12
    Views:
    342
    Robert Klemme
    Dec 9, 2010
  5. Venugopal
    Replies:
    11
    Views:
    1,516
    Tassilo v. Parseval
    Nov 5, 2003
Loading...

Share This Page