Finance Validators

Financial validators including Luhn algorithm for credit cards, currency formatting, and tax calculations.

28 code snippets available

Luhn Algorithm (Credit Card)

finance

Validates credit card numbers using checksum.

#payment#algorithm#validation
ts
const luhnCheck = (num: string): boolean => {
  let arr = (num + '').split('').reverse().map(x => parseInt(x));
  let lastDigit = arr.splice(0, 1)[0];
  let sum = arr.reduce((acc, val, i) => (i % 2 !== 0 ? acc + val : acc + ((val * 2) % 9) || 9), 0);
  return (sum + lastDigit) % 10 === 0;
};

Format Currency

finance

Formats number as currency with locale.

#format#money
ts
const formatCurrency = (amount: number, locale = 'en-US', currency = 'USD'): string => 
  new Intl.NumberFormat(locale, { style: 'currency', currency }).format(amount);

Calculate Tax

finance

Calculates tax amount from base price.

#tax#calculation
ts
const calculateTax = (amount: number, rate: number): number => amount * (rate / 100);

Bitcoin Address

finance

Legacy & Segwit.

#crypto
ts
const isValid = (s: string): boolean => /^(bc1|[13])[a-zA-HJ-NP-Z0-9]{25,39}$/.test(s);

Ethereum Address

finance

0x + 40 hex chars.

#crypto
ts
const isValid = (s: string): boolean => /^0x[a-fA-F0-9]{40}$/.test(s);

Credit Card (Simple)

finance

13-19 digits.

#payment
ts
const isValid = (s: string): boolean => /^[0-9]{13,19}$/.test(s);

IBAN

finance

International Bank Account.

#banking
ts
const isValid = (s: string): boolean => /^[A-Z]{2}\d{2}[A-Z0-9]{4}\d{7}([A-Z0-9]?){0,16}$/.test(s);

SWIFT/BIC

finance

Bank Identifier Code.

#banking
ts
const isValid = (s: string): boolean => /^[A-Z]{6}[A-Z0-9]{2}([A-Z0-9]{3})?$/.test(s);

ISIN

finance

International Securities ID.

#investing#stock
ts
const isValid = (s: string): boolean => /^[A-Z]{2}[A-Z0-9]{9}[0-9]$/.test(s);

CUSIP

finance

North American Security ID.

#investing#stock
ts
const isValid = (s: string): boolean => /^[0-9A-Z]{9}$/.test(s);

ABA Routing Number

finance

US Bank Routing 9 digits.

#banking#us
ts
const isValid = (s: string): boolean => /^((0[0-9])|(1[0-2])|(2[1-9])|(3[0-2])|(6[1-9])|(7[0-2])|80)([0-9]{7})$/.test(s);

VAT (Generic EU)

finance

EU VAT number format.

#tax#eu
ts
const isValid = (s: string): boolean => /^[A-Z]{2}[A-Z0-9+*]{2,12}$/.test(s);

IFSC Code (India)

finance

Bank Branch Code.

#india#bank
ts
const isValid = (s: string): boolean => /^[A-Z]{4}0[A-Z0-9]{6}$/.test(s);

Currency Code (ISO)

finance

3-letter ISO 4217 code.

#currency#iso
ts
const isValid = (s: string): boolean => /^[A-Z]{3}$/.test(s);

Solana Address

finance

Solana wallet address.

#crypto#solana
ts
const isValid = (s: string): boolean => /^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(s);

Cardano Address

finance

Cardano (ADA) address.

#crypto#cardano
ts
const isValid = (s: string): boolean => /^addr1[a-z0-9]+$/.test(s);

XRP Address

finance

Ripple wallet address.

#crypto#xrp
ts
const isValid = (s: string): boolean => /^r[1-9A-HJ-NP-Za-km-z]{24,34}$/.test(s);

Litecoin Address

finance

Litecoin wallet.

#crypto#litecoin
ts
const isValid = (s: string): boolean => /^[LM3][a-km-zA-HJ-NP-Z1-9]{26,33}$/.test(s);

Dogecoin Address

finance

Dogecoin wallet.

#crypto#dogecoin
ts
const isValid = (s: string): boolean => /^D[5-9A-HJ-NP-U][1-9A-HJ-NP-Za-km-z]{32}$/.test(s);

Polkadot Address

finance

Polkadot wallet.

#crypto#polkadot
ts
const isValid = (s: string): boolean => /^1[a-zA-Z0-9]{47}$/.test(s);

Cosmos Address

finance

Cosmos (ATOM) address.

#crypto#cosmos
ts
const isValid = (s: string): boolean => /^cosmos1[a-z0-9]{38}$/.test(s);

Tron Address

finance

Tron (TRX) wallet.

#crypto#tron
ts
const isValid = (s: string): boolean => /^T[a-zA-Z0-9]{33}$/.test(s);

MICR Code (India)

finance

9-digit MICR.

#banking#india
ts
const isValid = (s: string): boolean => /^\d{9}$/.test(s);

Sort Code (UK)

finance

UK bank sort code.

#banking#uk
ts
const isValid = (s: string): boolean => /^\d{2}-\d{2}-\d{2}$/.test(s);

BSB (Australia)

finance

Australian bank code.

#banking#australia
ts
const isValid = (s: string): boolean => /^\d{3}-\d{3}$/.test(s);

CLABE (Mexico)

finance

Mexican bank account.

#banking#mexico
ts
const isValid = (s: string): boolean => /^\d{18}$/.test(s);

CNAPS (China)

finance

China bank code.

#banking#china
ts
const isValid = (s: string): boolean => /^\d{12}$/.test(s);

Bank Account (Generic)

finance

8-17 digit account.

#banking#account
ts
const isValid = (s: string): boolean => /^\d{8,17}$/.test(s);

About Finance Validators

Our finance validation snippets are designed to handle the most common validation scenarios you'll encounter in modern software development. Each snippet is thoroughly tested, optimized for performance, and follows industry best practices.

All validators are available in multiple programming languages including JavaScript, TypeScript, Python, Go, PHP, C#, and Rust. Simply copy the code snippet, adapt it to your specific needs, and integrate it into your project. Every snippet is MIT licensed—free for personal and commercial use.

Browse Other Categories