Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save helabenkhalfallah/13fa174b9d4b6cfa4bc08849c29fb23b to your computer and use it in GitHub Desktop.
Save helabenkhalfallah/13fa174b9d4b6cfa4bc08849c29fb23b to your computer and use it in GitHub Desktop.
Universal Matcher
const universalMatcher = pattern => value => (
value ?
(value.match(pattern)&& value.match(pattern).length >= 1 ? true : false)
:false
);
const floatPattern = /^[0-9]*[,.][0-9]+$/;
const intPattern = /^[0-9]*$/;
const alphaNumeric = /^[A-Za-z0-9]$/;
const isInteger = universalMatcher(intPattern);
const isFloat = universalMatcher(floatPattern);
const isAlphanumeric = universalMatcher(alphaNumeric);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment