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

Question

Question

JavaScript Regex in Collection

asked on June 26, 2017 Show version history

Hello All,

I have been going through the Answers Forums trying to work out what I am doing wrong. I have a Form that has a db lookup to return students details. This fills in a Collection that contains Student, DOB and Class.  When there is more than one student in the family it creates a new collection.

What I am trying to do is reformat the DOB using JavaScript Regex. The value that is in the db is something like '03/01/2000 00:00:00'. I need to get rid of the '00:00:00'. I created a new field in the group called D.O.B. and gave it the css of D2. The original DOB has a css of D1.

This is the JavaScript that I have been trying..

 

$(document).ready(function(){
  $('.upperCase input').focusout(function() {
    $( this ).val($( this ).val().toUpperCase());
  });
 
  //*Changes Date of Birth with Regex
  var re = new RegExp("(\\d\\d\\/\\d\\d\\/\\d\\d\\d\\d)\\s00:00:00");
 
  $('.D1 input').on('change', function() {
    var pm = $(this).val().match(re);
    $('.D2 input').val(pm[1]).trigger('change');
  });
});
 

Any hints and assistance will be appreciated.

 

Jonathan

 

0 0

Replies

replied on June 27, 2017

Hi Jonathan,

Are you having issues with the JavaScript itself, or the pattern? If it's the pattern, try this:

([^ ]*)

This is basically saying, "return anything that's not a space", which captures everything up to the first space. I tested it out and it works fine with the example you provide.

Good luck,

Rob

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

Sign in to reply to this post.