1.0.8 • Published 3 months ago

persian-yup-ts v1.0.8

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

Persian Yup Rules

A TypeScript utility package providing custom validation rules for Persian-specific data using Yup.

Installation

You can install the package using either Yarn or npm:

# Using Yarn
yarn add persian-yup-ts

# Or using npm
npm install persian-yup-ts

Usage

To use persian-yup-ts in your project, follow these steps:

  1. Create a Yup utility file:

    In your project, create a utils/yup.ts file and set up Yup with custom messages and rules:

    import { makeYup } from "persian-yup-ts";
    
    const yup = makeYup({
        messages: {
            mobile: "Invalid Mobile",
            // ... add your custom messages here
        }
    });
    
    export default yup;
  2. Use the customized Yup instance in your forms:

    Import the custom Yup instance in your form validation schemas:

    import yup from "@/utils/yup";
    
    const SCHEMA = yup.object({
        mobile: yup.string().mobile(),
        // ... other rules
    });

Available Validation Rules

persian-yup-ts provides a set of custom validation rules tailored for Persian data formats. Here’s a list of the available rules:

Rule NameUsage ExampleDescription
nationalCodeyup.string().nationalCode()Validates Iranian national identification codes.
mobileyup.string().mobile()Validates Iranian mobile phone numbers.
telephoneyup.string().telephone()Validates Iranian landline telephone numbers.
ibanyup.string().iban()Validates Iranian IBANs.
postalCodeyup.string().postalCode()Validates Iranian postal codes.

License

This package is open-source and available under the MIT License.