Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7309095
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:40:07+00:00 2026-05-28T23:40:07+00:00

i need some help to solve my problem. I’ve got 2 input field with

  • 0

i need some help to solve my problem. I’ve got 2 input field with a mask ( http://digitalbush.com/projects/masked-input-plugin/ ) like that > 12/2010 ( mm/yyyy ).

I want that user could register form when a date is valid or leave blank, and send an alert in a div when a date is invalid.

It’s working fine if i’ve got 1 field, but when i have 2 field, if user enter a valid date in the second, he can register the form.

Else, if you have any idea to restrict end date that can be before the start date …

Thanks for any help 😉

My HTML code :

<form id="blockdate">
<div>date start: <input class="date" type="text"></div>
<div>date end: <input class="date2" type="text"></div>
<div><input class="submit" type="submit"></div>
<div id="msg"></div>
</form>

My JS code :

        function verifyDate(datevalue) {

      var done = false;

      if(datevalue != null || datevalue != ''){
        var tmp = datevalue.split('/');
        var month = tmp[0];
        var year = tmp[1];

       if(month >= 1 && month <= 12){
       if(year >= 1990 && year <= 2099){
           clean();
           done = true;
          }
          else {
            $('#msg').html('Year invalid 1900 - 2099.');
          }
       } else {
          $('#msg').html('Month invalid');
       }     
    } if (datevalue < 1 ) {
        done = true;
    }

    return done;
  }
function verifyDate2(datevalue2) {

      var done = false;

      if(datevalue2 != null || datevalue2 != ''){
        var tmp = datevalue2.split('/');
        var month = tmp[0];
        var year = tmp[1];

       if(month >= 1 && month <= 12){
       if(year >= 1990 && year <= 2099){
           clean();
           done = true;
          }
          else {
            $('#msg').html('Year invalid 1900 - 2099.');
          }
       } else {
          $('#msg').html('Month invalid');
       }     
    } if (datevalue2 < 1 ) {
        done = true;
    }

    return done;
  }



  function clean() {
     $('#msg').html('');
  }

    jQuery(function($) {
     $(".date").mask("99/9999");   

       $('.blockdate').submit(function() {
          var datevalue = $('.date').val();
          var datevalue2 = $('.date2').val();
          return verifyDate(datevalue);
       });

       $(".date").change(function(){
        var datevalue = $(this).val();
          if(datevalue.length == 7) {
            verifyDate(datevalue);
          } else {
            clean();
          }
      });


    jQuery(function($) {
     $(".date2").mask("99/9999");   

       $('.blockdate').submit(function() {
          var datevalue2 = $('.date2').val();
          return verifyDate2(datevalue2);
       });

       $(".date2").change(function(){
        var datevalue2 = $(this).val();
          if(datevalue2.length == 7) {
            verifyDate2(datevalue2);
          } else {
            clean();
          }
      });

    });

    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T23:40:07+00:00Added an answer on May 28, 2026 at 11:40 pm

    I can slightly simplify your task by providing a small regex.

    `^([0]?\d|1[0-2])/(199\d|20\d{2})$`
    

    use it this way

    function TestDate(input) {
        var pattern = /^([0]?\d|1[0-2])\/(199\d|20\d{2})$/;
        return pattern.test(input);
    }
    

    It checkes weather the first part, i.e. lies between 1 and 12 and the second part between 1990 and 2099.

    EDIT

    After you have tested the correctness of the format you can see the range as follows

    function RangeOk (lowerDate, upperDate) {
        return GetNumeric(lowerDate) < GetNumeric(upperDate);
    }
    
    function GetNumeric(input) {
        var parts = input.split("/");
        var yearNum = parseInt(parts[1]) * 12;
        // Get rid of leading 0 if exists
        // It can be there as the pattern above allows it.
        yearNum += parseInt(parts[0].replace(/0(\d)/, "$1"));
        return yearNum;
    }
    

    There is a small math trick.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well i need some help here i don't know how to solve this problem.
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Need some help to solve this. I have a gridview and inside the gridview
Need some help with this problem in implementing with XSLT, I had already implemented
I need some help regarding algorithm for randomness. So Problem is. There are 50
i need some help with a little problem that occurred today. To show the
I need help, any ideas? Firstly i want to hide some input element when
I have a problem and i need some ideas to solve it: I have
I need some help with a mySQL statement. I've got a mySQL table that
Need some help about with Memcache. I have created a class and want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.