I'm trying to make the text of an input be formatted by dividing the 48 numbers into blocks of 6 numbers, for example:
00000000000000000000000000000000000000000000
becomes
000000-000000-000000-000000-000000-000000-000000-000000
These numbers are returned with a $response after submitting a form with CURL.
For some reason when the result returns it is not in this format, I need to erase a number and rewrite it so that it is corrected and in the correct format.
This is the code I'm using:
JS
$(window).on("load",
function () {
$("#resID").on("change paste input", function (e) {
var t = this.value.replace(/\D/g, "");
48 == t.length ? (this.value = t.match(new RegExp(".{1," + t.length / 6 + "}", "g")).join("-")) : (this.value = t)
});
});
HTML
<div class="response">
<?php if($response != ''){ ?>
<input type="search" class="form-control" id="resID" style="text-align: center;" value="<?php echo $response; ?>" data-clipboard-target="#resID" href="#" readonly>
<?php } ?>
</div>
In short, it is formatting correctly but I need to update the numbers by deleting the last one and typing it in again.
Does anyone know what to be wrong?