tags:

views:

39

answers:

2

dear all.. i want after i have been type 123A0001-123A0100 the result is 100. Or if 123A0123-123A0200 the result is 78. how do i do that?please help.

thanks before.

+2  A: 
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(...)).

J-P
how if var str= '123x0001-123x0023'?
klox
@klox, in that case you'd want to change `str.match(/\d+/g)` to `str.match(/\d+(?=-|$)/g)`.
J-P
i change my question.
klox
A: 

There is a calculation plug-in for jQuery.

Calculation plugin

rdkleine