jquery - Extract a number from a string? (Javascript) -


var amount = "(21)"; 

how go getting number? have gotten work with...

var amountresult = amount.substring(1, amount.length-1); 

...but feels incorrect.

what's better, more flexible way if not surrounded 2 characters?

thanks!

using regular expression more flexible:

var amountresult = amount.match(/\d+/)[0]; 

and turn number:

var amountresult = parseint(amount.match(/\d+/)[0], 10); 

Comments

Popular posts from this blog

c# - OpenXML hanging while writing elements -

php - regexp cyrillic filename not matches -

sql - Select Query has unexpected multiple records (MS Access) -