-1

I am trying to replace the leading zero from a input field.

I am trying this but getting no luck

var regex = replace(/^0+/, "");
joshuahornby10
  • 4,222
  • 8
  • 36
  • 52

3 Answers3

0

You don't have a string in your example. Try something like this:

var foo = '012345';
var bar = foo.replace(/^0+/, '');
Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
0

Your regex is correct try using like this:

$ele.val(function(i, val) {
    return val.replace(/^0+/, "");//sets the value of each element to the original value without 0 padding
});
megawac
  • 10,953
  • 5
  • 40
  • 61
0

Something like this:

$("field_id").val($("field_id").val().replace(/^0+/, ""));

or this:

$("field_id").val(function(i, val){ return val.replace(/^0+/, ""); });
Ωmega
  • 42,614
  • 34
  • 134
  • 203