SunQuest
 
       MS SQL Server
  Home arrow MS SQL Server arrow Page 4 - Using Masks to Block Bad Data
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
Moblin 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

Using Masks to Block Bad Data
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2007-07-09

    Table of Contents:
  • Using Masks to Block Bad Data
  • Input Masks
  • Using a Ready-Made Mask
  • Creating Your Own Mask

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    Using Masks to Block Bad Data - Creating Your Own Mask


    (Page 4 of 4 )

    The Input Mask wizard provides a fairly limited set of choices. If you want to use a mask with your own type of information (like a special customer code that your business uses), then you’ll have to create your own mask.

    Creating a mask’s fairly easy, but it can take a bit of fiddling before you nail down exactly the result you want. You have two basic options:

    1. Type or edit the mask directly in the Input Mask field property.
    2. Launch the Input Mask wizard, choose a mask to use as a starting point (as described on page 125), and then tweak it in step 2. This approach has the advantage that you can test your mask in the Try It box before you save it as part of your table.

    Every mask’s built out of three types of characters:

    1. Placeholders designate where you type in a character.
    2. Special characters give additional instructions that tell Access how to treat a part of the mask. 
    3. Literals are all other characters, which are really just decoration to help make the value easier to interpret.

    In the previous example, the phone number mask was !(999) 000-000. The characters 9 and 0 are placeholders—they represent where you type in the digits of the phone number. The parentheses, space, and dash are just formatting niceties—they’re the literals. And the exclamation mark’s the only special character. It tells Access that characters should be entered into the mask from left to right, which is the standard option and the only one that really makes sense for a phone number.

    To help you sort all this out, refer to the following tables. Table 4-1 shows all the placeholders you can use in an input mask. Table 4-2 shows other special characters. Everything else is automatically a literal character.

    Table 4-1.  Special Characters for an Input Mask

    Character

    Description

    0

    A required digit (0 through 9).

    9

    An optional digit (0 through 9).

    #

    An optional digit, a plus sign (+), or a minus sign (–)

    L

    A required letter.

    ?

    An optional letter.

    A

    A required letter or digit.

    a

    An optional letter or digit.

    &

    A required character of any type (including letters, numbers, punctuation, and so on).

    C

    An optional character of any type (including letters, numbers, punctuation, and so on).

    Table 4-2.  Special Characters for an Input Mask

    Character

    Description  

    !

    Indicates that the mask’s filled from left to right when characters are typed in. This is the default, so this character’s not required (although the prebuilt masks include it).

    <

    Converts all characters that follow to lowercase.

    >

    Converts all characters that follow to uppercase.

    \

    Indicates that the following character should be treated as a literal. For exam-ple, the # character has a special meaning in masks. Thus, if you want to actu-ally include a # in your mask, you need to use \#. Sometimes, this character’s used before a placeholder even when it’s not needed. You may see a phone mask that has the character sequence \- instead of just -. Both are equivalent.

    Password

    Creates a password entry box. Any character you type in the box is stored as the character but displayed as an asterisk (*). When using this option, you can’t include anything else in your mask.

    Here are a few sample masks to get you started:

    1. (000) 000-000. A phone number that requires the area code digits. This mask’s different from the phone number mask that the Input Mask wizard uses. That mask replaces the first three 0 characters with 9, making the area code optional.
    2. 00000-9999. A U.S. zip code, which consists of five required digits followed by a hyphen and (optionally) four more digits.
    3. L0L 0L0. A British or Canadian postal code, which is a pattern of six characters that alternate between characters and digits, like M6S 3H2.
    4. 99:00:00 >LL. A mask for entering time information into a Date/Time field. It’s made up of two digits for the hour and two digits for the minute. The last two characters are always displayed in uppercase (thanks to the > character), and are meant to be AM or PM. (Technically, this mask doesn’t prevent the user from flouting the system and typing in two different characters. However, if you enter a time like 12:30 GM, Access complains that it can’t convert your entry into the Date/Time data type, as required for the field.)
    5. 099.099.099.099. An IP (Internet Protocol) address, which identifies a computer on a network. An IP address is written as four values separated by periods. Each value must have at least one digit, and can have up to three. This pattern’s represented in the mask by 099 (one required digit, followed by two optional digits).
    6. Password. A mask that allows ordinary, unlimited text, with one difference. All characters are displayed as asterisks (*), to hide them from prying eyes.

    Masks can also have two optional bits of information at the end, separated by semicolons (;).

    The second section’s a number that tells Access whether or not it should store the literal characters for the mask in the record. (This is the last question that the Input Mask wizard asks.) If you leave this piece out or use the number 1, then Access stores only the characters that someone types in. If you use the number 0, then Access stores the full text with the literals.

    The third section supplies the placeholder character. If you leave this section out, then Access uses the familiar underscore.

    Here’s a mask that uses these two extra bits of information:

      (000) 000-000;1;#

    Here, the second section’s 1, and the third section’s #. This mask’s for phone numbers, and it stores literals (in this case, two parentheses, a space, and a dash) and uses the number sign for a placeholder instead of the underscore.

    Please check back tomorrow for the continuation of this article.


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · This article is an excerpt from the book "Access 2007: The Missing Manual,"...
     

    Buy this book now. This article is excerpted from chapter four of Access 2007: The Missing Manual, written by Matthew MacDonald (O'Reilly, 2006; ISBN: 0596527608). Check it out today at your favorite bookstore. Buy this book now.

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway