I need a jquery script section that checks to see if the first digit of a textbox entered number string is a '0' and eliminate it if so. For example "044055" needs to become "44055"
+4
A:
Like this:
$(':text.Number').change(function() {
$(this).val(function(index, oldVal) { return oldVal.replace(/^0+/, ''); });
});
SLaks
2010-04-21 15:38:23
This removes multiple leading zeros. IMO, it's not clear from @sadmicrowave's post whether he wants to do that... although he probably does.
Chris Farmer
2010-04-21 15:50:31
+4
A:
>>> parseInt("044055", 10)
44055
Update
I guess I should add some explanations. The above is a method to extract an integer from a string. It takes for granted that the string actually contains a number.
Álvaro G. Vicario
2010-04-21 15:40:59
Thats pretty neat, and it seems to work, though I'm not sure how adding '10' to the parseInt function makes that work....could you explain what the 10 does.....does changing the 10 to other numbers change the parseInt function?
sadmicrowave
2010-04-21 16:00:27