Validators
60+ validatori organizzati per categoria. La sintassi è "required|email|min:5|max:100".
Sintassi
// Stringa pipe-separated
ValidationService.validate(value, 'required|email|min:5')
// I validatori restituiscono chiavi i18n
// { isValid: false, errors: ['validation.core.required'] }
// { isValid: false, errors: ['validation.core.min|min:5'] }
Dalla 2.12.0 un nome di regola non registrato è segnalato in qualsiasi posizione della stringa: in Node con NODE_ENV=development validate() lancia un errore, altrove restituisce validation.core.unknownValidator e il campo non è valido. Prima, dopo la prima posizione, veniva ignorato in silenzio. Dettagli e nomi da non usare (alphanum, same, accepted, date_before, ...) in ValidationService → Regole sconosciute; l'elenco esatto dei nomi registrati è ValidationService.getAvailableValidators().
Categorie
| Categoria | Validatori |
|---|---|
| core | required, min, max, minItems, maxItems, length, between, pattern, enum, range, regex |
| string | alpha, alphanumeric, slug, hex, base64, json |
| numeric | numeric, integer, positive, negative |
| date | date, before, after, time, cronexpression, daterange, seasonaldate, businesshours, minDate, maxDate |
| format | email, url, phone, color, semver, mime, geolocation, vatnumber, version, timestring, language, currency, hexcolor, semantic |
| italian | codicefiscale, partitaiva, codicefiscaleorpartitaiva, cap |
| financial | iban, creditcard, creditcardexpiry, swift, sepamandate, bic, cvv |
| network | ipaddress, macaddress, hostname, uuid, socialsecuritynumber, coordinates, imsi, imei, port, cidr |
| security | username, password, strong, passwordpolicy |
| documents | nationalid, passportnumber, vehicleregistration, driverlicense |
| file | filesize, filetype, filemimetype, sizerange |
| other | isbn, upc, ean, gtin, sku |
| custom | ValidationService.registerValidator() |