M
M
McThinker2020-05-13 12:53:18
JavaScript
McThinker, 2020-05-13 12:53:18

How to substitute * in the middle of the card number?

I want to write a credit card number mask, send it to the server with asterisks too. The problem is that val doesn't change

<input name="paymentCard" class="form-control" type="number" placeholder="**** **** **** ****" id="paymentCard">


function paymentCard() {
  if ($('#paymentCard').val() === "") {
    return '<?= lang("not_completed")?>';
  } else {
    const str = $('#paymentCard').val();
    const regex = /(?<=\d{4})\d(?=\d{4})/gm;
    const subst = `*`;
    return str.replace(regex, subst);
  }
}

$('#paymentCard').on('keyup', function () {
  paymentCard()
});



тут поклацать


what's wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question