Connecting Tech Pros Worldwide Help | Site Map

Avoid All Capital Letters in Guestbook

  #1  
Old July 20th, 2005, 02:13 PM
Carlos Marangon
Guest
 
Posts: n/a
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
  #2  
Old July 20th, 2005, 02:13 PM
Keith Bowes
Guest
 
Posts: n/a

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.

  #3  
Old July 20th, 2005, 02:13 PM
McKirahan
Guest
 
Posts: n/a

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>



  #4  
Old July 20th, 2005, 02:14 PM
McKirahan
Guest
 
Posts: n/a

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>


  #5  
Old July 20th, 2005, 02:33 PM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

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,}[] -@^-`\{-~[]*)+$/.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 :)
Closed Thread