You are viewing limited content. For full access, please sign in.

Question

Question

Can I lock the date field to only allow the MM/DD/YYYY format

asked on August 30, 2015

I am using a date field on a form.  Even though I have it as a date field I still have users who won't change their way and enter the format of YYYY/MM.  I want to lock the field to only accept MM/DD/YYYY format to force the users to adapt.  Any idea how I can do that?  Because the form is only printed (through java) and not submitted, nothing stops it as invalid.

 

0 0

Replies

replied on August 31, 2015 Show version history

Add the class datecheck to your field "Destruction Date" then add the following into your javascript.

$(document).ready(function(){

  $('.datecheck').on('blur', 'input', validatedate);
    
    function validatedate() {
    text = $('.datecheck input'); 
    if (/\d+\/\d+\/\d{4}/.test(text))
    {// good input
    }
      else { // bad input
        $('.datecheck input').val('Please use mm/dd/yyyy format');
      }
    };

});

 

This will validate the input and change the value of the field to the message, "Please use dd/mm/yyyy format' whenever focus is shifted out of the date picker window.

 

Edit to your desire, you can use a pop-up dialog box, like what Laserfiche does to provide the red text notification of invalid input, instead of assigning the above text as well.

https://jqueryui.com/dialog/

 

Cheers

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.