Regular expressions:

var numberPattern = /\d+/g;

'something102asdfkj1948948'.match( numberPattern )

This would return an Array with two elements inside, '102' and '1948948'. Operate as you wish. If it doesn't match any it will return null.

To concatenate them:

'something102asdfkj1948948'.match( numberPattern ).join('')

Assuming you're not dealing with complex decimals, this should suffice I suppose.

Answer from meder omuraliev on Stack Overflow
🌐
UI Bakery
uibakery.io › regex-library › numbers-only
Numbers Only Regex: Match Digits Only in JavaScript and Python
If your input contains other text and you want to extract numeric parts instead of validating the entire value, use a different regex: ... Use ^\d+$ for validation and \d+ for extraction. They solve different problems. ... This pattern finds digits anywhere inside a string, so it would match ...
Discussions

javascript - Regex to check whether a string contains only numbers - Stack Overflow
hash = window.location.hash.substr(1); var reg = new RegExp('^[0-9]$'); console.log(reg.test(hash)); I get false on both "123" and "123f". I would like to check if the hash only contains numbers. D More on stackoverflow.com
🌐 stackoverflow.com
javascript - Return only numbers from string - Stack Overflow
I have a value in Javascript as var input = "Rs. 6,67,000" How can I get only the numerical values ? Result: 667000 Current Approach (not working) var input = "Rs. 6,67,000"; var res = str.repl... More on stackoverflow.com
🌐 stackoverflow.com
regex - How to get only number in javascript? - Stack Overflow
CopyClick Here ... The above code only replaces the first dollar sign, but I have two dollar signs with number. How can I get 75 and 300 separately? ... Save this answer. ... Show activity on this post. You can just get all the numbers from the string, like this · Copyconsole.log('$75 - $300'.match(/(\d+)/g)); # [ '75', '300' ] Note: This simple RegEx ... More on stackoverflow.com
🌐 stackoverflow.com
regex - Javascript regular expression to allow only numbers upto 10 digits, string and special charecters are not allowed - Stack Overflow
I am working on JavaScript regular expressions and as per my need text box accept only 10 digit numbers but string and special character are not allowed I tried this it but didn't work for me. More on stackoverflow.com
🌐 stackoverflow.com
🌐
W3Resource
w3resource.com › javascript › form › all-numbers.php
JavaScript: HTML Form validation - checking for all numbers
July 24, 2026 - To get a string contains only numbers (0-9) we use a regular expression (/^[0-9]+$/) which allows only numbers. Next, the match() method of the string object is used to match the said regular expression against the input value.
🌐
Stack Overflow
stackoverflow.com › questions › 9011524 › regex-to-check-whether-a-string-contains-only-numbers
javascript - Regex to check whether a string contains only numbers - Stack Overflow
hash = window.location.hash.substr(1); var reg = new RegExp('^[0-9]$'); console.log(reg.test(hash)); I get false on both "123" and "123f". I would like to check if the hash only contains numbers. D...
🌐
Coding Beauty
codingbeautydev.com › home › posts › how to check if a string contains only numbers in javascript
How to Check if a String Contains Only Numbers in JavaScript
September 5, 2022 - To check if a string contains only numbers in JavaScript, call the test() method on this regular expression: ^\d+$. The test() method will return true if the string contains only numbers.
🌐
CodePen
codepen.io › jSilverize › pen › wWpmrO
JS | Only Number Regex
/* Styles from Foundation Framework: ... JavaScript Editor · Minimize JavaScript Editor · Fold All · Unfold All · /* * Only Numbers function */ function onlyNumbers(text) { // Replace regex '/[^0-9]/g' text = text.replace(/[^0-9]/g, ''); // Set to HTML var inputResult = ...
🌐
Javatpoint
javatpoint.com › javascript-only-number-regex
JavaScript only Number Regex - javatpoint
JavaScript only Number Regex with javascript tutorial, introduction, javascript oops, application of javascript, loop, variable, objects, map, typedarray etc.
Find elsewhere
🌐
TutorialsPoint
tutorialspoint.com › regular-expression-to-match-numbers-only-in-javascript
Regular expression to match numbers only in JavaScript?
November 15, 2022 - <html> <body> <h3>Validate Phone ... validatePhone() { var phone = document.getElementById("phoneInput").value; var numbersOnly = new RegExp('^[0-9]+$'); var validationDiv = document.getElementById("validation"); // Clear previous ...
🌐
EncodedNA
encodedna.com › javascript › how-to-get-numbers-from-a-string-in-javascript.htm
How to Get Numbers from a String in JavaScript
One of the simplest ways of extracting numbers from a given string in JavaScript is using Regex or Regular Expressions. Let us assume I have a string value, a name, suffixed with some random numbers. ... I want to extract the number 4874 from the above string and there are two simple methods to this. Similar example: How to filter out only numbers in an Array using pure JavaScript
🌐
Medium
medium.com › @Eun90 › how-can-you-find-only-numbers-in-a-string-in-javascript-34379cee8e25
How can you find only numbers in a string in javascript | by Eun | Medium
November 13, 2022 - How can you find only numbers in a string in javascript To check whether there are numbers or not in a string in JS, you need to know RegExp (Regular expression) A regular expression is a pattern of …
🌐
Regex Tester
regextester.com › 21
Check if a string only contains numbers - Regex Tester/Debugger
Undo & Redo with {{getCtrlKey()}}-Z / Y. Search for & rate Community patterns. ... extended (x) extra (X) single line (s) unicode (u) Ungreedy (U) Anchored (A) dup subpattern names(J) ... Match string not containing string Match elements of a url Match an email address Match or Validate phone number Match dates (M/D/YY, M/D/YYY, MM/DD/YY, MM/DD/YYYY) Regex Tester isn't optimized for mobile devices yet.
🌐
Tpoint Tech
tpointtech.com › javascript-only-number-regex
JavaScript only Number Regex - Tpoint Tech
March 17, 2025 - The javascript regex is used to validate the form on the web page. We can use the validation for the numbers in the string using the javascript function.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › extract-a-number-from-a-string-using-javascript
Extract a Number from a String using JavaScript - GeeksforGeeks
JavaScript · // Function to extract numbers function myGeeks() { // Input string let str = "jhkj7682834"; console.log(str) // Using match with regEx let matches = str.match(/(\d+)/); // Display output if number extracted if (matches) { console.log(matches[0]); } } // Function call myGeeks(); Output ·
Published: July 11, 2025
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript extract number from string | regex & replace function example
JavaScript extract number from string | RegEx & Replace function example
May 16, 2021 - Simply use a regular expression in replace function to get numbers from string in JS. Regular expression for extracting a number is (/(d+)/)
🌐
W3Schools
w3schools.com › jsref › jsref_regexp_0-9.asp
JavaScript RegExp Characters [0-9]
new RegExp("[0-9]", "g") or simply: /[0-9]/g · Use the [^0-9] expression to find any character that is NOT a digit. Do a global search for the number "1" in a string: let text = "12121212"; let pattern = /[1]/g; Try it Yourself » · Regular ...
🌐
Reddit
reddit.com › r/regex › only numbers, no blanks
r/regex on Reddit: Only numbers, no blanks
February 8, 2023 -

Is there a regular expression to check for only numerical characters and no blanks? The furthest I’m able to get is this: [0-9]*$ Unfortunately it doesn’t account for blanks. These didn’t work for me either: \d+$ /-?\d+$/

I’m using this regex to confirm a SharePoint field (formatted as single line of text) contains only numbers even though some inputs are alphanumeric or blank.

🌐
regex101
regex101.com › library › mG3lT2
only numbers
Please complete this security check to continue to regex101.