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

Question

Question

Forms- Regular Expression to pass last two digits to another form field

asked on May 18, 2016 Show version history

Hello,

I am very new to javascript and I am attempting in Forms to use a regular expression to parse the last two digits of one field(#q139) and pass it to another(#q156).  Can anyone see where I am going wrong?

 

$(document).ready(function () {
  $('#q139').on("change", function() {
RegEx = (\d\d)\Z.exec('#q139');
temp = RegEx[1];
$('#q156').val(temp);

 

Thanks in advance!

0 0

Replies

replied on May 18, 2016 Show version history

Your regular expression syntax appears off. I would think you would need something like:
 

var RegEx = /\d\d$/;
var Result = RegEx.exec($('#q139').val());

See here for more details:

http://www.w3schools.com/jsref/jsref_obj_regexp.asp

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

Sign in to reply to this post.