@uireact/validator v2.8.0
@UiReact tools
These are a set of tools that we created and are exported as part of the @uireact library, these tools doesn't need the foundation / view packages to work as they don't export UI, instead are helper functions that could work on any React/Typescript project.
@uireact/validator
This packages exports a class for validating data. This is commonly used to validate data received from a form.
We have added multiple validations like:
- required
- type
- phone
- greaterThan
- range
- dateRange
- length
- lessThan
For the full documentation you can visit @uireact/validator.
Usage
- You need to create a schema where each field has its own set of rules:
import { UiValidator } from '@uireact/validator';
const validator = new UiValidator();
const schema = {
firstName: validator.ruler().isRequired('The first name is required')
};
- Then you can call the function
validate()
with your data and schema objects:
const data = {
firstName: 'Felipe'
};
const result = validator.validate(schema, data);
- The
result
will bring 2 properties:
passed - If the validation successeded errors - The errors found during the validation
The errors
property is keyed with properties that matches the field name of the data object passed:
console.log(`Passed: ${result.passed}`);
if (result.errors) {
const { firstName } = result.errors;
if (firstName?.length > 0) {
console.log(`Error: ${firstName[0].message}`)
}
}
What is @UiReact library?
This is a React UI library, that defines a customizable theme object that powers all colorations, texts, sizes, etc.. Across your react application.
We are built using framer-motion for great animations and styled-components for easy CSS management.
You should visit our docs page for all information @uireact docs.
6 months ago
6 months ago
6 months ago
6 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago