www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-21-2009, 02:58 PM
    FattiFat FattiFat is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 7
    Regular Expression form field validation

    Hi Everyone,
    I need to add a form field validation using Javascript to make sure a text field's value is entered correctly. I lack expertise in this field, so all of this Javascript code is looking like a different language to me...

    What I need is to validate the field so that it is the following pattern "mmyy" (basically a 4 digit numeric value). I was thinking that function validateValue is the way to go - but I am unsure how to write the rest. Can anyone help me out?
    Reply With Quote
      #2  
    Old 11-21-2009, 09:57 PM
    JavaServlet JavaServlet is offline
    Registered User
     
    Join Date: Jun 2009
    Posts: 92
    Quote:
    Originally Posted by FattiFat View Post
    Hi Everyone,
    I need to add a form field validation using Javascript to make sure a text field's value is entered correctly. I lack expertise in this field, so all of this Javascript code is looking like a different language to me...

    What I need is to validate the field so that it is the following pattern "mmyy" (basically a 4 digit numeric value). I was thinking that function validateValue is the way to go - but I am unsure how to write the rest. Can anyone help me out?
    Here is one way to do it using test method. I also included a replace method to trim the value.

    Code:
    function validater(fld) {
      var fourDigits = /^\d{4}$/;
      var formValue = document.demo.monthYear.value;
      var trimmed = formValue.replace(/^\s+|\s+$/g, '');
    
      if (fourDigits.test(trimmed))
      {
        alert("Four Digits");
      }
      else
      {
        alert("Not four digits.");
      } 
      return false; 
    }
    Reply With Quote
      #3  
    Old 11-22-2009, 11:34 AM
    FattiFat FattiFat is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 7
    Awesome! That is what I needed. Thanks.
    Reply With Quote
      #4  
    Old 11-28-2009, 07:58 PM
    FattiFat FattiFat is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 7
    One more question......

    Is there anyway to specify that the digits must meet a certain criteria? For example, since this is for an expiration date, I do not want someone to enter a month and date that has already passed.

    Can this be done in the expression or would I need some additional Javascript coding to validate the field?
    Reply With Quote
      #5  
    Old 11-29-2009, 06:48 AM
    unigogo unigogo is offline
    Registered User
     
    Join Date: Jan 2009
    Posts: 24
    need some additional Javascript coding
    __________________
    1, 2, 3, 4, 5 column CSS layout generators
    generating clear codes
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 04:43 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.