Package Exports
- joi-country-state
- joi-country-state/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (joi-country-state) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
joi-country-state
A Joi extension that provides easy validation for country and state fields.
Installation
npm install joi-country-stateUsage
1. Country Validation
import BaseJoi from 'joi';
import { countryValidator } from 'joi-country-state';
const Joi = BaseJoi.extend(countryValidator);
const countrySchema = Joi.object({
country: Joi.country().required(),
});
const result = countrySchema.validate({ country: 'IN' });2. State Validation
import BaseJoi from 'joi';
import { stateValidator } from 'joi-country-state';
const Joi = BaseJoi.extend(stateValidator);
const stateSchema = Joi.object({
state: Joi.state().forCountry('IN').required(),
});
const result = stateSchema.validate({ state: 'TN' });3. Country and State Validation with Reference
import BaseJoi from 'joi';
import { countryValidator, stateValidator } from 'joi-country-state';
const Joi = BaseJoi
.extend(countryValidator)
.extend(stateValidator);
const schema = Joi.object({
country: Joi.country().required(),
state: Joi.state().forCountry(Joi.ref('country')).required(),
});
const result = schema.validate({ country: 'IN', state: 'TN' });