-
Notifications
You must be signed in to change notification settings - Fork 0
Predefined validators
Léo Millon edited this page Mar 13, 2019
·
1 revision
JCV comes with a library of pre-defined validators :
- contains
- starts_with
- ends_with
- regex
- uuid
- not_null
- not_empty
- boolean_type
- string_type
- number_type
- array_type
- object_type
- url
- url_ending
- url_regex
- templated_url
- templated_url_ending
- templated_url_regex
- date_time_format
- (required) the text to search for
Actual JSON :
{
"field_name": "Hello world!"
}
Expected JSON :
{
"field_name": "{#contains:llo wor#}"
}
- (required) the text to search for
Actual JSON :
{
"field_name": "Hello world!"
}
Expected JSON :
{
"field_name": "{#starts_with:Hello#}"
}
- (required) the text to search for
Actual JSON :
{
"field_name": "Hello world!"
}
Expected JSON :
{
"field_name": "{#ends_with:world!#}"
}
- (required) the regex pattern
Actual JSON :
{
"field_name": "Hellowurld !!!"
}
Expected JSON :
{
"field_name": "{#regex:.*llo ?w.r.*#}"
}
Actual JSON :
{
"field_name": "8525aa57-d491-41e2-b065-013aaacb24f7"
}
Expected JSON :
{
"field_name": "{#uuid#}"
}
Actual JSON :
{
"field_name": ""
}
Expected JSON :
{
"field_name": "{#not_null#}"
}
Actual JSON :
{
"field_name": " "
}
Expected JSON :
{
"field_name": "{#not_empty#}"
}
Actual JSON :
{
"field_name": true
}
Expected JSON :
{
"field_name": "{#boolean_type#}"
}
Actual JSON :
{
"field_name": "some text"
}
Expected JSON :
{
"field_name": "{#string_type#}"
}
Actual JSON :
{
"field_name": 123.45
}
Expected JSON :
{
"field_name": "{#number_type#}"
}
Actual JSON :
{
"field_name": ["Value 1", "Value 2"]
}
Expected JSON :
{
"field_name": "{#array_type#}"
}
Actual JSON :
{
"field_name": { "some_sub_field": "some value" }
}
Expected JSON :
{
"field_name": "{#object_type#}"
}
Actual JSON :
{
"field_name": "http://some.url:9999/path?param"
}
Expected JSON :
{
"field_name": "{#url#}"
}
- (required) url ending
Actual JSON :
{
"field_name": "http://some.url:9999/path?param"
}
Expected JSON :
{
"field_name": "{#url_ending:/path?param#}"
}
- (required) regex pattern
Actual JSON :
{
"field_name": "http://some.url:9999/path?param"
}
Expected JSON :
{
"field_name": "{#url_regex:^.+some\\.url.+/path\\?param$#}"
}
Actual JSON :
{
"field_name": "http://some.url:9999/path{?param}"
}
Expected JSON :
{
"field_name": "{#templated_url#}"
}
- (required) templated url ending
Actual JSON :
{
"field_name": "http://some.url:9999/path{?param}"
}
Expected JSON :
{
"field_name": "{#templated_url_ending:/path{?param}#}"
}
- (required) regex pattern
Actual JSON :
{
"field_name": "http://some.url:9999/path{?param}"
}
Expected JSON :
{
"field_name": "{#templated_url_regex:^.+some\\.url.+/path\\{\\?param\\}$#}"
}
- (required) the date time pattern (a predefined patterns or a custom pattern)
- (optional) the language tag (IETF BCP 47) for the custom pattern
Actual JSON :
{
"date_time_predefined_format": "10:15:30+01:00",
"date_time_format": "3 Feb 2011",
"date_time_format_with_locale": "3 févr. 2011"
}
Expected JSON :
{
"date_time_predefined_format": "{#date_time_format:iso_time#}",
"date_time_format": "{#date_time_format:d MMM uuu#}",
"date_time_format_with_locale": "{#date_time_format:d MMM uuu;fr-FR#}"
}
Pattern name | Description | Example |
---|---|---|
basic_iso_date |
Basic ISO date | 20111203 |
iso_local_date |
ISO Local Date | 2011-12-03 |
iso_offset_date |
ISO Date with offset | 2011-12-03+01:00 |
iso_date |
ISO Date with or without offset '2011-12-03+01:00'; | 2011-12-03 |
iso_local_time |
Time without offset | 10:15:30 |
iso_offset_time |
Time with offset | 10:15:30+01:00 |
iso_time |
Time with or without offset '10:15:30+01:00'; | 10:15:30 |
iso_local_date_time |
ISO Local Date and Time | 2011-12-03T10:15:30 |
iso_offset_date_time |
Date Time with Offset | 2011-12-03T10:15:30+01:00 |
iso_zoned_date_time |
Zoned Date Time | 2011-12-03T10:15:30+01:00[Europe/Paris] |
iso_date_time |
Date and time with ZoneId | 2011-12-03T10:15:30+01:00[Europe/Paris] |
iso_ordinal_date |
Year and day of year | 2012-337 |
iso_week_date |
Year and Week | 2012-W48-6 |
iso_instant |
Date and Time of an Instant | 2011-12-03T10:15:30Z |
rfc_1123_date_time |
RFC 1123 / RFC 822 | Tue, 3 Jun 2008 11:05:30 GMT |
Symbol | Meaning | Presentation | Examples |
---|---|---|---|
G |
era | text | AD; Anno Domini; A |
u |
year | year | 2004; 04 |
y |
year-of-era | year | 2004; 04 |
D |
day-of-year | number | 189 |
M/L |
month-of-year | number/text | 7; 07; Jul; July; J |
d |
day-of-month | number | 10 |
Q/q |
quarter-of-year | number/text | 3; 03; Q3; 3rd quarter |
Y |
week-based-year | year | 1996; 96 |
w |
week-of-week-based-year | number | 27 |
W |
week-of-month | number | 4 |
E |
day-of-week | text | Tue; Tuesday; T |
e/c |
localized day-of-week | number/text | 2; 02; Tue; Tuesday; T |
F |
week-of-month | number | 3 |
a |
am-pm-of-day | text | PM |
h |
clock-hour-of-am-pm (1-12) | number | 12 |
K |
hour-of-am-pm (0-11) | number | 0 |
k |
clock-hour-of-am-pm (1-24) | number | 0 |
H |
hour-of-day (0-23) | number | 0 |
m |
minute-of-hour | number | 30 |
s |
second-of-minute | number | 55 |
S |
fraction-of-second | fraction | 978 |
A |
milli-of-day | number | 1234 |
n |
nano-of-second | number | 987654321 |
N |
nano-of-day | number | 1234000000 |
V |
time-zone ID | zone-id | America/Los_Angeles; Z; -08:30 |
z |
time-zone name | zone-name | Pacific Standard Time; PST |
O |
localized zone-offset | offset-O | GMT+8; GMT+08:00; UTC-08:00; |
X |
zone-offset 'Z' for zero | offset-X | Z; -08; -0830; -08:30; -083015; -08:30:15; |
x |
zone-offset | offset-x | +0000; -08; -0830; -08:30; -083015; -08:30:15; |
Z |
zone-offset | offset-Z | +0000; -0800; -08:00; |
p |
pad next | pad modifier | 1 |
' |
escape for text | delimiter |
|
'' |
single quote | literal | ' |
[ |
optional section start | ||
] |
optional section end | ||
# |
reserved for future use | ||
{ |
reserved for future use | ||
} |
reserved for future use |