niner
asked on
Get the number value from string
How do I get the value of a number from a string in Javascript? Like with 'ABC12' I just want to return the 12.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you want to only get the first number/decimal in the string, you can use the following:
<script type="text/javascript">
var str = "ABC12g345";
str = parseFloat(str.replace(/^\
alert(str);
</script>
The regular expression will strip out any non-numbers in the beginning of the string, and then take the numbers left at the beginning. Hope one of the two helps.