Created
August 13, 2020 20:34
-
-
Save neyasbltb88/98460d8dfb10cba344de6a4939281431 to your computer and use it in GitHub Desktop.
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 | |
hex = /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/, | |
hexa = /^#[0-9a-fA-F]{4}([0-9a-fA-F]{4})?$/, | |
hexOrHexa = /^#([0-9a-fA-F]{3}|[0-9a-fA-F]{4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/, | |
rgb = /^rgb\(((0|[1-9][\d]?|1[\d]{0,2}|2[\d]?|2[0-4][\d]|25[0-5]),){2}(0|[1-9][\d]?|1[\d]{0,2}|2[\d]?|2[0-4][\d]|25[0-5])\)$/, | |
rgba = /^rgba\(((0|[1-9][\d]?|1[\d]{0,2}|2[\d]?|2[0-4][\d]|25[0-5]),){2}(0|[1-9][\d]?|1[\d]{0,2}|2[\d]?|2[0-4][\d]|25[0-5]),(0|0\.[0-9]+[1-9]|0\.[1-9]+|1)\)$/ | |
export const testPattern = { | |
date: v => /^-?[\d]+\/[0-1]\d\/[0-3]\d$/.test(v), | |
time: v => /^([0-1]?\d|2[0-3]):[0-5]\d$/.test(v), | |
fulltime: v => /^([0-1]?\d|2[0-3]):[0-5]\d:[0-5]\d$/.test(v), | |
timeOrFulltime: v => /^([0-1]?\d|2[0-3]):[0-5]\d(:[0-5]\d)?$/.test(v), | |
hexColor: v => hex.test(v), | |
hexaColor: v => hexa.test(v), | |
hexOrHexaColor: v => hexOrHexa.test(v), | |
rgbColor: v => rgb.test(v), | |
rgbaColor: v => rgba.test(v), | |
rgbOrRgbaColor: v => rgb.test(v) || rgba.test(v), | |
hexOrRgbColor: v => hex.test(v) || rgb.test(v), | |
hexaOrRgbaColor: v => hexa.test(v) || rgba.test(v), | |
anyColor: v => hexOrHexa.test(v) || rgb.test(v) || rgba.test(v) | |
} | |
export default { | |
testPattern | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment