Skip to main content

extractNumber

A function that returns a string stripped of all characters except numbers when string is entered.


Interface

const extractNumber: (value: string) => string

Usage

import { extractNumber } from '@devgrace/utils';

const str1 = extractNumber('abc123sd45'); // '12345'
const str2 = extractNumber('1 23 sd 4 5'); // '12345'
const str3 = extractNumber('🥲'); // ''
const str4 = extractNumber(' '); // ''