MS SQL Server
  Home arrow MS SQL Server arrow Page 3 - 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 
Moblin 
JMSL Numerical Library 
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


    Using Masks to Block Bad Data - Using a Ready-Made Mask


    (Page 3 of 4 )

    The easiest way to get started with masks is to use one of the many attractive options that Access has ready for you. This method’s great, because it means you don’t need to learn the arcane art of mask creation.

    Here’s what you need to do to pick out a prebuilt mask:

    1. In Design view, select the text field where you want to apply the mask.

      For this test, try a PhoneNumber field. 
    2. Look for the Input Mask field property. Click inside the field.

      When you do, a small ellipsis (…) button appears at the left edge, as shown in Figure 4-9. 


      Figure 4-9.
      The ellipsis (...) button (circled) is just the way Access tells you that you don’t need to fill in this value by hand. Instead, you can click the ellipsis and pop up a wizard (like the Input Mask wizard) or some sort of helpful dialog box.
    3. Click the ellipsis button.

      The Input Mask wizard starts (see Figure 4-10).


      Figure 4-10.
      The Input Mask wizard starts with a short list of commonly used masks. Next to every mask, Access shows you what a sample formatted value looks like. Once you select a mask, you can try using it in the Try It text box. The Try It text box
      gives you the same behavior that your field will have once you apply the mask.
       
    4. Choose the mask you want from the list of options.

      In this case, choose the first item in the list (Phone Number).


      Note: Don’t see what you want? You’ll need to create your own, using the tips on page 128. If you see one that’s close but not perfect, select it. You can tweak the mask in the wizard’s second step. 

    5. Click Next.

      The wizard’s second step appears (see Figure 4-11). 
    6. If you want, you can change the mask or the placeholder character.

      To change the mask, you’ll need to learn what every mask character means. Page 129 explains it all.

      Input Masks


      Figure 4-11.
      The phone number mask is !(999) 000-000. Each 9 represents an optional number from 0 to 9. Each 0 represents a required number from 0 to 9. So according to this mask, (123) 456-7890 is a valid phone number, as is 123-4567, but (123) 456
      isn’t.

      You use the placeholder to show the empty slots where you enter information. The standard choice is the underscore. Optionally, you can use a space, dash, asterisk, or any other character by typing it in the “Placeholder character” box. 
    7. Click Next.

      If you’re adding a mask to a text field, then the wizard’s final step appears (see Figure 4-12).

      If you’re adding a mask to a date field, then Access doesn’t need to ask you how to store the information—it already knows. In this case, you can jump to step 9 and click Finish. 


      Figure 4-12.
      The final step lets you choose how the data in your field is chosen—with or without the mask symbols.
    8. Choose how you want to store the value in this field.

      The standard choice is to store just the characters you’ve typed in (in other words, everything you type into the field). If you use this option, the placeholders aren’t included. For example, the phone number (416) 123-4567 is stored as 4161234567. This option saves a little space, and it also lets you change the mask later on to present the information in a slightly different way.

      You could also store the mask complete with all the extra characters. Then a phone number’s stored complete with hyphens, dashes, and spaces, like (416) 123-4567. This approach isn’t nearly as flexible because you can’t change the mask later. 
    9. Click Finish.

      The final mask appears in the Input Mask field property.

      Before going any further, you may want to make sure that the length you’ve reserved for your field matches the mask. In the phone number example, you need a Field Size of 10 if you’ve chosen to store unformatted values (because there are 10 digits), or a Field Size of 14 for the whole shebang, complete with placeholders (one dash, one space, and two parentheses). 
    10. Switch back to the Datasheet view, and click Yes when Access asks you to save changes.

      Your input mask is now in place.

    Note: Access uses the input mask information to control how you enter information in the datasheet. However, it’s possible to circumvent the mask by entering the information in other ways. You could, for instance, create a form (as described in Part Four), and switch off the mask. A mask’s not an absolute guarantee against invalid data—if you want such a guarantee, then you need a validation rule instead.


    More MS SQL Server Articles
    More By O'Reilly Media


       · 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 3 hosted by Hostway