ASP.NET
  Home arrow ASP.NET arrow Page 2 - Improved Input Validation
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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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? 
ASP.NET

Improved Input Validation
By: Harish Kamath (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 15
    2004-03-31

    Table of Contents:
  • Improved Input Validation
  • Common Applications
  • Regular Joe
  • The Number Game
  • Custom Craft
  • validateNumber() function
  • A Closer Look
  • A Comedy of Errors
  • Server Control

  • 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


    Improved Input Validation - Common Applications


    (Page 2 of 9 )

    For example, one of the most common applications of regular expressions is to check whether or not a user's email address, as entered into an online form, is in the correct format. If it is, the form is processed. If it's not, a warning message pops up asking the user to correct the error. Regular expressions thus play an important role in the decision-making routines of Web applications - although, as you'll see, they can also be used to great effect in complex find-and-replace operations.

    A regular expression usually looks something like this:


    /war/

    All this does is match the pattern "war" in the text it's applied to.

    How about something a little more complex? Try this:


    /ri+/

    This would match the words "ring", "right" and "river-bed". And although it's a pretty silly example, you have to admit that there's truth to it - after all, wasn't the "ring" found "right" at the bottom of the "river-bed"?

    The "+" that you see above is the first of what are called "meta-characters" - these are characters that have a special meaning when used within a pattern. Similar to the "+" meta-character, we have "*" and "?" - these are used to match zero or more occurrences of the preceding character, and zero or one occurrence of the preceding character, respectively.
     
    In case all this seems a little too imprecise, you can also specify a range for the number of matches. For example, the regular expression:


    /mat{2,6}/

    would match "matting" and "mattress", but not "matrix". The numbers in the curly braces represent the lower and upper values of the range to match. You can leave out the upper limit for an open-ended range match.

    Now, regular expressions are a topic in themselves - I don't plan to spend any more time on them (although you certainly can, here). Instead, let's look at what this has to do with ASP.NET validation, next.

    More ASP.NET Articles
    More By Harish Kamath (c) Melonfire


     

    ASP.NET ARTICLES

    - Adding Content to a Static ASP.NET Website
    - Building a Static ASP.NET Website in a Basic...
    - Develop Your First ASP.NET Website with Visu...
    - Run ASP.NET in Windows XP Home with Cassini ...
    - How to Test a Web Application
    - How to Add Code and Validation Controls to a...
    - Working in Source and Split Views to Build a...
    - How to Build a Web Form for a One-Page Web A...
    - How to Develop a One-Page Web Application
    - An ASP.NET Web Application in Action
    - Developing ASP.NET Web Applications
    - An Introduction to ASP.NET Web Programming
    - Introduction to the ADO.NET Entity Framework...
    - Completing an In-Text Advertising System und...
    - Programming an In-Text Advertising System un...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek