Javascript 从jquery中的下拉列表中提取值只需要数字值

Javascript 从jquery中的下拉列表中提取值只需要数字值,javascript,jquery,drop-down-menu,split,Javascript,Jquery,Drop Down Menu,Split,大家好,我正在使用jquery从dropdownlist获取值 这是我的jquery代码 var priceValue = $("#ddlprice option:selected").text(); 我得到了价值 Valvet 100美元 但是我只想从这个值中得到100,那么我如何从中提取出准确的值呢。 谢谢使用正则表达式获取数字 /\d+/g this will search for number in a given string var priceValue=Valvet$10

大家好,我正在使用jquery从dropdownlist获取值 这是我的jquery代码

var priceValue = $("#ddlprice option:selected").text(); 
我得到了价值 Valvet 100美元

但是我只想从这个值中得到100,那么我如何从中提取出准确的值呢。
谢谢

使用正则表达式获取数字

/\d+/g this will search for number in a given string 
var priceValue=Valvet$100;
console.log/\d+/g.execpriceValue[0] 如果这个值是100,就像这样

<select id="ddlprice">
  <option value="100">Valvet ($100)</option>
</select>
可能重复的
function getNumbers(inputString){
    var regex=/\d+\.\d+|\.\d+|\d+/g, 
        results = [],
        n;

    while(n = regex.exec(inputString)) {
        results.push(parseFloat(n[0]));
    }

    return results;
}
var priceValue = $("#ddlprice option:selected").text(); 
console.log(getNumbers(priceValue));