Reputation: 805
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 ?
Upvotes: 0
Views: 373
Reputation: 1905
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)
Upvotes: 0
Reputation: 232
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:
$(document).ready(function(){
$("button").click(function(){
var oldprice = $("#price").html();
var newprice = oldprice.replace(/[^0-9\.]/g, '');
$("#price").html(newprice);
});
});
Upvotes: 0