Every line of 'regex currency' 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.
36 export function currencyToRegex( 37 thousandSeparators = [' ', '.', ',', "'", '`'], 38 decimalNumbers = 2, 39 decimalSeparators = ['.', ','], 40 thousandGroupNumbers = 3 41 ) { 42 const thousandSeparatorsRegex = arrayOfStringsToRegex( 43 thousandSeparators 44 ).join('|'); 45 const decimalSeparatorsRegex = arrayOfStringsToRegex(decimalSeparators).join( 46 '|' 47 ); 48 49 const integerRegex = `(\\d{0,${thousandGroupNumbers - 50 1}}(?:(?:${thousandSeparatorsRegex})?\\d{${thousandGroupNumbers}})*)`; 51 const decimalRegex = 52 decimalNumbers > 0 53 ? `(?:(?:${decimalSeparatorsRegex})(\\d{0,${decimalNumbers}}))?` 54 : ''; 55 56 return `^${integerRegex}${decimalRegex}$`; 57 }
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
61 function getRegex (isDecimal: boolean): RegExp { 62 return new RegExp( 63 isDecimal 64 ? `^(0|[1-9]\\d*)(\\${KEYS.DECIMAL}\\d*)?$` 65 : '^(0|[1-9]\\d*)$' 66 ); 67 }