Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Avoid All Capital Letters in Guestbook

Reply
Thread Tools

Avoid All Capital Letters in Guestbook

 
 
Keith Bowes
Guest
Posts: n/a
 
      01-06-2004
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.

 
Reply With Quote
 
 
 
 
Carlos Marangon
Guest
Posts: n/a
 
      01-06-2004
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
 
Reply With Quote
 
 
 
 
McKirahan
Guest
Posts: n/a
 
      01-06-2004
"Carlos Marangon" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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>



 
Reply With Quote
 
McKirahan
Guest
Posts: n/a
 
      01-06-2004
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>


 
Reply With Quote
 
Thomas 'PointedEars' Lahn
Guest
Posts: n/a
 
      01-15-2004
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to convert capital letters to lower case Chris Mayhew NZ Computing 25 01-25-2012 04:08 PM
Re: How can I add spaces where ever I have capital letters? Eric Wertman Python 2 05-09-2008 01:28 PM
Function to convert all of the small letters to the capital? Ebi C++ 2 02-05-2005 12:59 AM
Changing from capital letters to small letters using perl Venugopal Perl Misc 11 11-05-2003 06:07 PM
Capital Letters Miguel Orrego ASP General 6 08-20-2003 02:27 PM



Advertisments