Concepts
Input
input is the object to be validated, it is the first parameter of the val
function.
RebbVal
support following datatypes:
Datatype in input
Boolean
Number
Include integer, long, float, double, all input numbers will be casted to BigDecimal(in Java implementation).
Date
In Java implementation,the input could been a java.uitl.Date
String
Rule
Rule is the second parameter of theval
function
A rule is just a string, the supported rule grammar are:
comparions: =, !=, >,<,>=,<=
between .. and ..
interval
in (array)
contains
not empty
max length
is (true, false, phone, email, ipv4,url, ect.)
is (custom function)
match (regex)
older than/younger than
starts with/ends with
Rules can be negated by using not
operation
Rules can be combined with and
, or
Datatype in rule
array
boolean
number
date
regex
string
Result
The result of the val
function is a boolean.
If result is true, means all rules are satisfied, if false, you can check errors by calling getErrors
function
Error
If the result of val
is false, or hasError
function returns true
, then the validataion failed.
You can call getErrors
function, which returns an array of string(in Java, an ArrayList<String>), to get the detail message.
Custom Validator
Write a class that implements com.rebb.val.IValidator
interface
In the run function, do your validate work and return a boolean as validation result.
After initialize the RebbVal
object, call registerCustomValidator
function
Timezone
When we deal with date, timezone is always the first consideration, you can set the timezone like this:
Last updated
Was this helpful?