need code for counting from string
i want after i have been type 123A0001-123A0100
the result is 100
.
Or if 123A0123-123A0200
th开发者_如何学Ce result is 78
.
how do i do that?please help.
thanks before.
var str = 'A0001-A0100',
match = str.match(/\d+/g);
if (match) {
alert(+match[1] - +match[0]);
}
+
(unary plus) will cast the string to a number (does the same as Number(...)
).
There is a calculation plug-in for jQuery.
Calculation plugin
精彩评论