Skip to main content
added 30 characters in body
Source Link
Sean Wessell
  • 3.5k
  • 1
  • 14
  • 20

I would handle the input, propertychange, and paste events. Then use regex to match for anything that begins with 0 and replace the current value with the value minus the leading 0.

http://jsfiddle.net/SeanWessell/5qxwpv6h/

$('input ').on('input propertychange paste', function (e) { var val = $(this).val() var reg = /^0/gi; if (val.match(reg)) { $(this).val(val.replace(reg, '')); } }); 

Bug fix reported by Kevin/Updated per recommendations of canon:

http://jsfiddle.net/SeanWessell/5qxwpv6h/1/http://jsfiddle.net/SeanWessell/5qxwpv6h/2/

$('input').on('input propertychange paste', function (e) { var reg = /^0^0+/gi; whileif ($(this).val()value.match(reg)) { $(this).val($(value = this).val()value.replace(reg, '')); } }); 

I would handle the input, propertychange, and paste events. Then use regex to match for anything that begins with 0 and replace the current value with the value minus the leading 0.

http://jsfiddle.net/SeanWessell/5qxwpv6h/

$('input ').on('input propertychange paste', function (e) { var val = $(this).val() var reg = /^0/gi; if (val.match(reg)) { $(this).val(val.replace(reg, '')); } }); 

Bug fix reported by Kevin:

http://jsfiddle.net/SeanWessell/5qxwpv6h/1/

$('input').on('input propertychange paste', function (e) { var reg = /^0/gi; while ($(this).val().match(reg)) { $(this).val($(this).val().replace(reg, '')); } }); 

I would handle the input, propertychange, and paste events. Then use regex to match for anything that begins with 0 and replace the current value with the value minus the leading 0.

http://jsfiddle.net/SeanWessell/5qxwpv6h/

$('input ').on('input propertychange paste', function (e) { var val = $(this).val() var reg = /^0/gi; if (val.match(reg)) { $(this).val(val.replace(reg, '')); } }); 

Bug fix reported by Kevin/Updated per recommendations of canon:

http://jsfiddle.net/SeanWessell/5qxwpv6h/2/

$('input').on('input propertychange paste', function (e) { var reg = /^0+/gi; if (this.value.match(reg)) { this.value = this.value.replace(reg, ''); } }); 
added 294 characters in body
Source Link
Sean Wessell
  • 3.5k
  • 1
  • 14
  • 20

I would handle the input, propertychange, and paste events. Then use regex to match for anything that begins with 0 and replace the current value with the value minus the leading 0.

http://jsfiddle.net/SeanWessell/5qxwpv6h/

$('input ').on('input propertychange paste', function (e) { var val = $(this).val() var reg = /^0/gi; if (val.match(reg)) { $(this).val(val.replace(reg, '')); } }); 

Bug fix reported by Kevin:

http://jsfiddle.net/SeanWessell/5qxwpv6h/1/

$('input').on('input propertychange paste', function (e) { var reg = /^0/gi; while ($(this).val().match(reg)) { $(this).val($(this).val().replace(reg, '')); } }); 

I would handle the input, propertychange, and paste events. Then use regex to match for anything that begins with 0 and replace the current value with the value minus the leading 0.

http://jsfiddle.net/SeanWessell/5qxwpv6h/

$('input ').on('input propertychange paste', function (e) { var val = $(this).val() var reg = /^0/gi; if (val.match(reg)) { $(this).val(val.replace(reg, '')); } }); 

I would handle the input, propertychange, and paste events. Then use regex to match for anything that begins with 0 and replace the current value with the value minus the leading 0.

http://jsfiddle.net/SeanWessell/5qxwpv6h/

$('input ').on('input propertychange paste', function (e) { var val = $(this).val() var reg = /^0/gi; if (val.match(reg)) { $(this).val(val.replace(reg, '')); } }); 

Bug fix reported by Kevin:

http://jsfiddle.net/SeanWessell/5qxwpv6h/1/

$('input').on('input propertychange paste', function (e) { var reg = /^0/gi; while ($(this).val().match(reg)) { $(this).val($(this).val().replace(reg, '')); } }); 
Source Link
Sean Wessell
  • 3.5k
  • 1
  • 14
  • 20

I would handle the input, propertychange, and paste events. Then use regex to match for anything that begins with 0 and replace the current value with the value minus the leading 0.

http://jsfiddle.net/SeanWessell/5qxwpv6h/

$('input ').on('input propertychange paste', function (e) { var val = $(this).val() var reg = /^0/gi; if (val.match(reg)) { $(this).val(val.replace(reg, '')); } });