formvalidator

    1.0.3 • Public • Published

    Form Validator

    Simple package for easy form validation.

    Installation

    npm install formvalidator

    or simply download and "require" this repository.

    Usage

    const FormValidator = require('formvalidator');
     
    const myForm = new FormValidator(settings);
     

    Sample settings

    [
      {
        fieldId: 'ammount',
        fieldValue: '0',
        validation: ['isEmpty', 'isInteger'],
        valid: true,
        isRequired: true
      },
      {
        fieldId: 'phone',
        fieldValue: '123456',
        validation: ['isEmpty', 'isInteger'],
        valid: true,
        isRequired: true
      },
      {
        fieldId: 'notes',
        fieldValue: '',
        validation: ['isEmpty', 'isLongEnough'],
        valid: true,
        isRequired: false
      },
      {
        fieldId: 'email',
        fieldValue: '111@gmail.com',
        validation: ['isEmpty', 'isEmail'],
        valid: true,
        isRequired: true
      },
      {
        fieldId: 'nip',
        fieldValue: '538-317-76-23',
        validation: ['isEmpty', 'isNip'],
        valid: true,
        isRequired: true
      },
      {
        fieldId: 'postcode',
        fieldValue: '11-000',
        validation: ['isEmpty', 'isPostCode'],
        valid: true,
        isRequired: true
      }
    ];

    Available Methods

    1. FormValidator:
    .checkForm();

    Checks if all required fields are valid without validating them.

    .validateForm();

    Validates all form fields and runs .checkForm().

    .getFormField(name);

    Returns a form field Object that was created using settings.

    1. FormField
    .validate()

    Validates the field using validation functions provided in settings.

    .set(property, value);

    After setting new property value, .validate() will be run.

    .get(property);

    Available validation functions

    isEmail(value);
    isEmpty(value);
    isInteger(value);
    isLongEnough(value, valueLength); //at the moment package only checks default length which is 10. TO DO
    isNip(value);
    isPositive(value);
    isPostCode(value);

    TO DO

    1. Validation functions api
    2. Passing more than one arguments to validation functions

    Keywords

    none

    Install

    npm i formvalidator

    DownloadsWeekly Downloads

    6

    Version

    1.0.3

    License

    ISC

    Last publish

    Collaborators

    • thetofiq