RegEx Collection

A collection of Regular Expressions that I use for my projects.

1. Digits Only

Code

const areDigitsOnly = (input: any) => new RegExp(/^[0-9]*$/).test(input);

Example

function handleChange(event: ChangeEvent<HTMLInputElement>) {
  const value = e.currentTarget.value;

  if (areDigitsOnly(value)) {
    console.log('Digits!');
  } else {
    console.log('Not all digits');
  }
}