How to use 'regex number only' in JavaScript

Every line of 'regex number only' 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
55function getNumber(parser) {
56 const number = parser.matchPattern(numberPattern);
57 if (number) return { v: +number };

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

35function isValidNumber(value) {
36 const regex = new RegExp('^[-]?[0-9]*$');
37 const result = regex.test(value);
39 return result;

Related snippets