JavaScript
  Home arrow JavaScript arrow Page 2 - Form Validation with JavaScript Regular Ex...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
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? 
JAVASCRIPT

Form Validation with JavaScript Regular Expressions (Part 2)
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 90
    2005-05-17

    Table of Contents:
  • Form Validation with JavaScript Regular Expressions (Part 2)
  • User-friendly enhancement
  • Defining the regular expressions
  • Testing the values submitted

  • 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


    Form Validation with JavaScript Regular Expressions (Part 2) - User-friendly enhancement


    (Page 2 of 4 )

    I haven’t included it in this example, but another user-friendly feature that would enhance this form would be a function using the focus method, which highlights all of the text in a field if that field is selected. This means that the user can easily retype any invalid answers. This example has been tested and found to work on MSIE, Netscape Navigator 7 and FireFox, so you can be sure that a wide base of visitors will find this form fully functional. 

    We can then build the following script that is inserted into the head of the document and called on submission of the form. If this page were to be used on the Internet, it would be a good idea to separate the script from the main document, and allow it to reside in its own file in a protected folder within the site’s directory structure (probably the scripts folder). This would be safer, as the file would not be directly viewable, and would therefore not expose the logic behind your validation scheme. Forms have traditionally been popular points of entry for hackers.

    First, you need to get all of your field inputs into variables that the script can work with. These will go at the very beginning of the validate() function:

    <script>

    function validate(){

    var fname = document.myForm.fname.value;

    var lname = document.myForm.lname.value;

    var house = document.myForm.house.value;

    var pcode = document.myForm.pcode.value;

    var telno = document.myForm.telno.value;

    var email = document.myForm.email.value;

    var verEmail = document.myForm.verifyEmail.value;

    var url = document.myForm.url.value;

    var dob = document.myForm.dob.value;

    More JavaScript Articles
    More By Dan Wellman


       · The email validation fails for long TLDs. Valid addresses such as me@mydomain.info...
       · Thanks for pointing those out, the validation routine passed all of the tets i threw...
       · var urlRegxp =...
       · The statement in your post looks fine, is there anything else on the page it could...
       · Thanks for reply. I found the problem and it might be of instest to future visitors...
       · Have you heard of any problems with the new info domain? Just wondering if the regex...
       · hii sir,this is kumar.till today i have lots of doubts on regular expression.but...
       · Thanks, glad you found the article interesting and useful :DDan Wellman
       · Hii Sir,THanks for those useful articles .My personal request is when ever you...
       · hi,your expression works goods and fine it helps me alot.thanks...
       · Dan, your email regex : var emailRegxp =...
       · Hi, thanks for pointing this out and useful to know that escaping the period could...
       · What I mean't was it should have caught abcd@abcd as an invalid email format but did...
       · oh, ok, excellent, thanks for providing the fix in that case :DDan Wellman
       · i got a project of web designing and it was the phase of form validation i found ur...
     

    JAVASCRIPT ARTICLES

    - More on JavaScript Array Objects
    - Methods of the DOM Location Object
    - The DOM Location Object Properties
    - Handling Remote Files with JavaScript Click ...
    - Using Click Interceptions with a Database-Dr...
    - Using JavaScript Click Interceptions in an I...
    - Using Click Interceptions with JavaScript
    - QuickSort in Action
    - Quicksort
    - Using Mod_Security to Protect Your Server
    - Detecting and Countering Server Intrusions
    - Securing Your Web Server
    - Building a Secure Web Server
    - Protecting the Server
    - Book Review: Learning the Yahoo! User Interf...


     
    Best Practices for Windows Vista Migration Presentation
    Dell and Microsoft recently held a series of face-to-face seminars entitled, &qu....

     
    Creating a Culture for Code Reuse
    If you oversee development teams you know that like it or not proprietary and ex....

     
    Keys to Web Application Acceleration: Advances in Delivery Systems
    Accelerate Web apps by up to 5x. Ensure significantly faster access to the Web a....

     
    Optimizing Application Monitoring
    Tired of finding out from your customers that you're offline? This white paper e....

     
    Solaris to Solaris Migration -- Migrating applications from Sun SPARC to Dell PowerEdge R900
    This comprehensive Migration Guide reviews the approach that Principled Technolo....

     





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
    Stay green...Green IT