Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing number from string

How do I split selected value, seperate the number from text in jQuery?

Example:

myselect contains c4

Just get only the number 4.

$('select#myselect').selectToUISlider({
      sliderOptions: {
        stop: function(e,ui) {
          var currentValue = $('#myselect').val();
          alert(currentValue);
          var val = currentValue.split('--)
          alert(val);

        }
      }
    });
like image 226
user683742 Avatar asked Dec 04 '22 20:12

user683742


1 Answers

You can use regex to pull only the numbers.

var value = "c4";
alert ( value.match(/\d+/g) );

edit: changed regex to /\d+/g to match numbers greater than one digit (thanks @Joseph!)

like image 155
Jim Schubert Avatar answered Dec 08 '22 15:12

Jim Schubert