Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do use regular expression replace remove the 0 start character?

I use this code to replace not numeric character,but when the number is start with 0,like "000001111" or "0000000", 0 will appear in the front.

I want to replace the 0 start number,how to fix my code? When all the input is 0,like this "00000000",keep only one 0,when input number like this "000234",keep 234.

My code:

<input id="text_target_value" maxlength="11" class="text-right number" type="text" onkeyup="value=value.replace(/[^\d]/g,'')";">

I only want to fix onkeyup.


1 Answers

You don't need regular expression. just use Number function like in the below example;

function relpacing($this) {
  $this.value = Number($this.value);
}
<input id="text_target_value" maxlength="11" class="text-right number" type="number" onkeyup="relpacing(this)">
like image 98
ferhado Avatar answered Apr 29 '26 12:04

ferhado