forked from quasarframework/quasar
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
patterns.js
31 lines (25 loc) · 1.17 KB
/
patterns.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// file referenced from docs
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
}