Created
May 15, 2021 22:25
-
-
Save helabenkhalfallah/13fa174b9d4b6cfa4bc08849c29fb23b to your computer and use it in GitHub Desktop.
Universal Matcher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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