Struct types can have validation rules. Let's define StudentReport again and put the validation rules in the struct.
Rule | Description | Example | Type |
---|---|---|---|
< | less than | x < 35 | int, long, number, string, date |
<= | less than or equals | x <= 35 | "” |
> | greater than | x > 35 | "” |
>= | greater than or equals | x >= 35 | "” |
== | equals | x == 35 | "” |
!= | not equals | x != 35 | "” |
contains | not equals | name.contains(‘ony’) | string |
maxlen | maximum length | name.maxlen(32) | string |
New validation rules can be added by writing Java classes.
There are some functions that can be used in a rule.
Rule | Description | Example | Type |
---|---|---|---|
len() | length | name.len() < 64 | string |
year() | year | orderDate.year() > 2015 | date |
month() | month | orderDate.month() > 3 | date |
day() | day (day of month) | orderDate.date() > 25 | date |
hour() | hour | orderDate.hour() > 5 | date |
minute() | minute | orderDate.minute() > 30 | date |
second() | second | orderDate.second() > 3 | date |
date() | date | orderDate > date(‘2019’) | date |