Create a Masked Input Control (cont.)

Exploring Textbox Behavior
The textbox is one of those great controls that is so simple, you sort of take it for granted that it will just always be there and always work the way you expect it to. Exactly what should you expect? Here's how an HTML textbox control behaves by default:

KeypressResult
A letter, number, space, or other character key A character appears in the textbox.
Backspace Removes the character before the cursor.
EnterSubmits a form.
Delete Removes the character after the cursor.
HomeMoves the cursor to the front of the textbox.
EndMoves the cursor to the end of the textbox.
Cursor Arrow KeysMoves the cursor around in the textbox.
Ctrl + CCopies the selected text to the clipboard.
Ctrl + XRemoves the highlighted text from the textbox and places it on the clipboard.
Ctrl + VInserts text on the clipboard into the textbox at the cursor position.
Ctrl + Z Undoes the last change to the textbox's contents.

Wow! The textbox sure does a lot, doesn't it? The difficulty in creating a masked input control for the textbox is, of course, that you have to take into account all of these different expected behaviors. You'll want to intercept some of the behaviors, but not others. The trick is to address each of these behaviors separately, so that the final data masking doesn't have any logical holes that allow users to enter invalid data (and you know that if there is a hole, some user, somewhere, will definitely find it).

In this article, you'll create a textbox into which users can enter only numbers. To ensure its suitability for Web applications, the control must work in Netscape Navigator 4.7x, Internet Explorer 5.0+, and Netscape 6.0+.


Introduction

Blocking Keystrokes

Introduction Exploring Textbox Behavior Blocking Keystrokes
Dealing with Special Keys Dealing with Cut, Copy, Paste, and Undo Don't Forget Paste Validation
Polishing the Mask    


 






 TALK BACK
Creating a masked edit text box in DTHML is not as straightforward as it seems at first. Do you know of other masked edit examples? Join the discussions at web.dhtml.scripting to get answers, make comments, or help others with their problems.
Click here to Join
Get the Code

MSDN DHTML Events Reference

MSDN DHTML Input Element Reference

Mozilla DOM Event Interface

Netscape DevEdge, "Form Validation with JavaScript 1.2 Regular Expressions"

Netscape DevEdge, "Form Validation with JavaScript 1.0"

MSDN Behaviors Reference





 
Sponsored Links

Advertising Info  |   Member Services  |   Contact Us  |   Help  |   Feedback  |   Site Map
Jupiterweb networks

internet.comearthweb.comDevx.comClickZ

Search Jupiterweb:

Jupitermedia Corporation has four divisions:
JupiterWeb, JupiterResearch, JupiterEvents, and JupiterImages

Copyright 2004 Jupitermedia Corporation All Rights Reserved.
Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

Jupitermedia Corporate Info | Newsletters | Tech Jobs | E-mail Offers

Copyright Information/Privacy Statement