Cvermule

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Thursday, 17 February 2005

Limiting Characters entered in an html text field Part 2

Posted on 11:55 by Unknown
This is another version of the checkKey() method in the previous posting. It is also usable on IE or Netscape. This function goes about comparing the current key to a string of allowed characters. If it is allowed, it returns true. Otherwise, it returns false. This function is allowing a-z, A-Z, 0-9, -, *, and a space. (Also the Home, End, Delete, and Arrow Keys.)

<script type="text/javascript">
function isValidKey(pEvent)
{
var key;
var keychar;
var lAllowedChars = "abcdefghijklmnopqrstuvwxyz0123456789-*' ";

if (window.event)
key = window.event.keyCode;
else if (pEvent)
key = pEvent.which;
else
return true;

keychar = String.fromCharCode(key).toLowerCase();

// control keys
if ((key==null) (key==0) (key==8)
(key==9) (key==13) (key==27))
return true;

// alphas, numbers, and allow characters
else if (((lAllowedChars).indexOf(keychar) > -1))
return true;
else
return false;
}
</script>
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

Categories

  • amazon
  • browser specific
  • coding
  • Eclipse
  • error
  • example
  • funny
  • google
  • grep
  • hacks
  • javascript
  • jott
  • music
  • null
  • phone
  • search
  • search engine
  • tip
  • tool
  • unix
  • web development
  • yui

Blog Archive

  • ►  2008 (5)
    • ►  September (1)
    • ►  August (1)
    • ►  July (1)
    • ►  June (1)
    • ►  January (1)
  • ►  2007 (6)
    • ►  December (1)
    • ►  September (1)
    • ►  July (1)
    • ►  June (1)
    • ►  March (2)
  • ►  2006 (10)
    • ►  November (1)
    • ►  August (1)
    • ►  May (2)
    • ►  April (4)
    • ►  March (2)
  • ▼  2005 (10)
    • ►  August (3)
    • ►  June (2)
    • ▼  February (5)
      • Limiting Characters entered in an html text field ...
      • Limiting Characters entered in an html text field ...
      • Accessing an Access Db using JavaScript
      • Date Validation with JavaScript
      • A lazy Day.
  • ►  2004 (9)
    • ►  October (2)
    • ►  September (7)
Powered by Blogger.

About Me

Unknown
View my complete profile