Wallflower Wallflower - 1 year ago 84
Javascript Question

JavaScript get number from string that contain '0' in front of number

If I have the string

how can I remove the PK and leading 0s to get just

Answer Source

Is this something like what you're looking for?

var code = "PK000019";
var code_num = parseInt(code.substr(2), 10); //returns 19

You can get the full product code back from the number like so:

var code_num = 19;
var code = "PK" + ("00000" + code_num).slice(-6); //returns PK000019
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download