Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Avoid All Capital Letters in Guestbook

Question posted by: Carlos Marangon (Guest) on July 20th, 2005 01:13 PM
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
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
Keith Bowes's Avatar
Keith Bowes
Guest
n/a Posts
July 20th, 2005
01:13 PM
#2

Re: Avoid All Capital Letters in Guestbook
Carlos Marangon wrote:[color=blue]
>
> 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?
>[/color]

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.


McKirahan's Avatar
McKirahan
Guest
n/a Posts
July 20th, 2005
01:13 PM
#3

Re: Avoid All Capital Letters in Guestbook
"Carlos Marangon" <area48@hotmail.com> wrote in message
news:2cfc228.0401052135.44d7d679@posting.google.co m...[color=blue]
> 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[/color]


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's Avatar
McKirahan
Guest
n/a Posts
July 20th, 2005
01:14 PM
#4

Re: Avoid All Capital Letters in Guestbook
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>



Thomas 'PointedEars' Lahn's Avatar
Thomas 'PointedEars' Lahn
Guest
n/a Posts
July 20th, 2005
01:33 PM
#5

Re: Avoid All Capital Letters in Guestbook
McKirahan wrote:
[color=blue]
> [...]
> if (Cap > 1) alert("Two consecutive capital letters!");[/color]

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,}[] Join Bytes!(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 :)

 
Not the answer you were looking for? Post your question . . .
183,905 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors