0

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.

1
  • no.i want if start from 1 code can read 0 Commented Jul 23, 2010 at 10:18

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

2 Comments

how if var str= '123x0001-123x0023'?
@klox, in that case you'd want to change str.match(/\d+/g) to str.match(/\d+(?=-|$)/g).
0

There is a calculation plug-in for jQuery.

Calculation plugin

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.