469,282 Members | 1,716 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,282 developers. It's quick & easy.

Avoid All Capital Letters in Guestbook

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
Jul 20 '05 #1
4 10530
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.

Jul 20 '05 #2
"Carlos Marangon" <ar****@hotmail.com> wrote in message
news:2c*************************@posting.google.co m...
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>

Jul 20 '05 #3
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>
Jul 20 '05 #4
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 :)
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.