js-laravel-validation
Useful for having consistent server side and client side validation with Laravel
All rules are base on documentation from https://laravel.com/docs/5.7/validation#available-validation-rules
Setup
Install: npm install js-laravel-validation
Usage
import { validateForm } from "js-laravel-validation";
const formData = {
username: {
value: "test1",
validation: "required|string"
},
password: {
value: null,
validation: "required|string"
}
};
const result = validateForm({ formData });
if (result.errors) {
console.log(result.errors);
}
Docs
Missing Rules
-
active_url
- This cannot be supported because JS does not support hostname lookups (dns_get_record in PHP)
- This could be implemented if there was a reliable way to host a small API to do the lookup
-
date_format
- This can be added with something like
return new Date(value).format(params[0]) === value;
- Unfortunately that isn't so easy in vanilla js atm
-
exists & unqiue
- These are both rules relating to the database
-
not_regex
(to come)
-
regex
(to come)
- Regex requires extra parsing to remove forward slashes around regex