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

Question

Question

JavaScript regex to format Form Field

asked on June 25, 2017 Show version history

I am trying to format a field in a Form that shows a Date Of Birth plus the time. I need to only show the date.

Example - 23/06/2000 00:00:00

I would imagine that the regex would be something like this - (\d\d\/\d\d\/\d\d\d\d)\s00:00:00

How do I use it with JavaScript?

 

 

 

0 0

Answer

SELECTED ANSWER
replied on June 25, 2017

Answered my own question - 

 

$(document).ready(function () {
 
  var re = new RegExp("(\\d\\d\\/\\d\\d\\/\\d\\d\\d\\d)\\s00:00:00");
 
  $('#q3 input').on('change', function() {
    var pm = $(this).val().match(re);
    $('#q42 input').val(pm[1]).trigger('change');
  });
});
 

0 0
replied on June 26, 2017 Show version history

If the time is always "00:00:00" you could also .replace() instead of regex.

var pm = $(this).val().replace(" 00:00:00","");
0 0

Replies

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

Sign in to reply to this post.