0

I have problem with string in Jquery. I have to convert for example '4444aaaa5555' string to '44445555'. I want to cut everything beside the numbers, is there a function for that ?

0

3 Answers 3

5
myString = myString.replace(/\D/g,'');
Sign up to request clarification or add additional context in comments.

Comments

0

jQuery doesn't have strict rules for string and int. (You don't need a C# thinking)

For deleting the letters and keeping the numbers, you can try this:

http://jsfiddle.net/L5S7Q/

$(document).ready(function(){
  $("button").click(function(){
    var oldprice = $("#price").html();
    var newprice = oldprice.replace(/[^0-9\.]/g, '');
    $("#price").html(newprice);
  });
});

Comments

0

You can do that with javascript using regex

   var number = yourstring.replace(/[^0-9]/g, '');

This will get rid of anything that's not [0-9]

if you want to make it as function

  function getNumber(param)
  {
      return   param.replace(/[^0-9]/g, '');
  }

you can acces this by

 var number =getNumber(yourstring)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.