JS hanya mengekstrak angka dari string
"1.23-45/6$7.8,9".replace(/[^0-9]/g,'')
// Response: "123456789"
Tarik
"1.23-45/6$7.8,9".replace(/[^0-9]/g,'')
// Response: "123456789"
thenum = "foo3bar5".match(/\d+/)[0] // "3"
var myInt = parseInt("10.256"); //10
var myFloat = parseFloat("10.256"); //10.256
str = "hello123!"
str.match(/(\d+)/)[1] //Best way to find first matching number in string ;)
function justNumbers(string) {
var numsStr = string.replace(/[^0-9]/g, '');
return parseInt(numsStr);
}
var input = "Rs. 6,67,000";
var number = justNumbers(input);
console.log(number); // 667000
Run code snippet
var regex = /\d+/g;
var string = "Any string you want!";
var matches = string.match(regex); // creates array from matches
if (matches){
// There is a digit in the string.
} else {
// No Digits found in the string.
}