10 examples of 'get number from string jquery' in JavaScript

Every line of 'get number from string jquery' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
1function number(input: string | number): number {
2 if (typeof input === 'string') {
3 return parseInt(input.replace(/^\D+/g, ''), 10);
4 }
5
6 return 0;
7}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

42function getNumber (str) {
43 str = str.replace(/(invert)|(brightness)|(blur)|(contrast)|(grayscale)|(sepia)|(threshold)|(gamma)?\(/g, '').replace(')', '')
44 if (str.indexOf('%') !== -1) {
45 return Number(str.replace('%', '')) / 100
46 } else if (str.indexOf('px') !== -1) {
47 return Number(str.replace('px', ''))
48 } else {
49 return Number(str)
50 }
51}
15function getNumFromStr(str) {
16 return `${str.match(/\d+/)[0]}`;
17}
2740function toNumber (str) {
2741 return parseInt(str, 10)
2742}
385function getInputNumber(elemId) {
386 var str = document.getElementById(elemId).value;
387 if (str == "")
388 return null;
389 var result = parseFloat(str);
390 if (!isFinite(result))
391 throw "Invalid number";
392 if (0 >= result)
393 throw "All inputs must be positive";
394 return result;
395}
15function getNumbers(string) {
16 if (isUndefined(string) || !isString(string)) {
17 return '';
18 }
19
20 return String(string).replace(/\D+/g, '');
21}
222function _getFirstNumByString(string) {
223 return parseInt(string.match(/-?\d+/)[0], 10);
224}
3function parseNumber(value) {
4 const num = parseInt(value.toString());
5 if (isNaN(num)) return 0;
6 return num;
7}
5function extractNumber(string) {
6 if (!regex.test(string)) {
7 console.error('Imagemagick\'s compare method failed');
8 console.error(string);
9 return Infinity;
10 }
11
12 var match = string.match(regex);
13 return +match[1];
14}
16function getNumber(numberEdit) {
17 var value = $('#' + numberEdit).val();
18 var number = parseInt(value);
19 if (!isNaN(number))
20 return number;
21
22 value = $('#' + numberEdit).attr('placeholder');
23 if (!isNaN(number))
24 return number;
25
26 return null;
27}

Related snippets