Reputation: 671
How can I use regex to parse the numeric value (104)
assigned to qtyAvail
in the below javascript?
<script>
var buyID = "302";
var qtyAvail = "104";
var outBehavior = "Default";
if (qtyAvail == "0") {
if (outBehavior.indexOf("Disallow") != -1) {
do this
} else if (outBehavior.indexOf("Allow") != -1) {
do that
}
}
</script>
Upvotes: 0
Views: 82
Reputation: 9752
You don't need to use a regular expression, you can just use the native parseInt javascript function:
parseInt(qtyAvail, 10); // the 2nd argument 10 means use base 10 (decimal, as opposed to hexadecimal or something else)
=> 104
Upvotes: 2