davidwaterston
4/20/2014 - 10:22 AM

Javascript: increment the number part of a text field e.g. take a text field containing "abc15" and increment it by 1 to return "abc16", "xy

Javascript: increment the number part of a text field e.g. take a text field containing "abc15" and increment it by 1 to return "abc16", "xyz99" will become "xyz100", etc. Really shouldn't be doing this but if you have to then this will do it.

See it in action: http://jsfiddle.net/davidwaterston/a8yXH/

var myString = "abc99";

newString = myString.replace(/\d+$/, function(n) { return ++n });