npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gdev-form-validation

v2.0.3

Published

A robust form validation library for js based applications. No js required.

Downloads

4

Readme

removal-ai-68a74532-f4d0-4b18-87c3-ffe7a11deffe-screenshot-2024-06-20-075650-19-Z4-RR.png pour la version francaise de ce document, visite notre site gdev.com

Gdev Form Validation

Gdev Form Validation is a dynamic and customizable form validation package designed to make form validation easy and flexible for developers. It provides multiple methods to handle form validation, including auto-validation, specific form validation, and validation as the user types both in English and French.

Installation

NPM

To install the package using npm, run:

npm install gdev_form_validation

CDN

To use the package via CDN, include the following in your HTML:

<!-- CSS for styling -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gdev_form_validator@latest/dist/validator.bundle.css">

<!-- JavaScript for validation -->
<script src="https://cdn.jsdelivr.net/npm/gdev_form_validator@latest/dist/autovalidate.bundle.js"></script>

Validation Response

when validation is completed, the package returns the response as an object in its simplest form so the developer can foward users input to the backend as object values:{} very easily.

onSuccess (if the validation rules have all been checked)

  {
      "status": "true",
      "values": {
          "field1_name_as_specified_in_validation_rule": "value1",
          "field2_name_as_specified_in_validation_rule": "value2",
          "field3_name_as_specified_in_validation_rule": "value3"
      }
  }

onError (if one of the validation rules failed)

  {
      "status": "false",
      "values": {}
  }

Usage

Auto Validation

To automatically validate all forms on a page:

  1. Include the auto-validator script in your HTML:

    <script src="https://cdn.jsdelivr.net/npm/gdev_form_validator@latest/dist/autovalidate.bundle.js"></script>

    make sure to provide unique id for each form to be validated and Gdev-lang = "fr or en" attribute for language to report errors.

  2. The validator will scan through all forms on the page and validate them based on rules specified in the HTML.

  3. To handle validation results, listen for the onValidationComplete event:

    const form1 = document.getElementById('your-form-id');
    form1.addEventListener('onValidationComplete', function(e) {
      console.log(window.validationResponse.your-form-id);
    });

Specific Form Validation

To validate a specific form:

  1. Import the validator script or install the package using npm as shown above:

    <script src="https://cdn.jsdelivr.net/npm/gdev_form_validator@latest/dist/validator.bundle.js"></script>
  2. Create a validator instance and call the validate method:

       
    import { FormValidation } from 'gdev_form_validation';
    
    const form = document.getElementById('yourFormId');
    const validator = new FormValidation(form, 'en'); // 'en' or 'fr' for language
    
    form.addEventListener('submit', (e) => {
      e.preventDefault();
      const result = validator.validate();
      console.log(result);
    });

Validate as User Types

To validate each input field as the user types:

  1. Call the validateEach() method on your validator instance:

    validator.validateEach();

Validation Rules

Specify validation rules directly in your HTML using the Gdev-props attribute in plain English. Here are some examples:

Text Input

<div class="gdev-field-wrapper">
    <input type="text" Gdev-props='{"type":"text","name":"username",minchar":10,"minWord":3}' />
    <div class="gdev-error"></div>
</div>

Password Input

<div class="gdev-field-wrapper">
    <input type="password" Gdev-props='{"type":"password","name":"password", "confirmWith": "name of confirm field"}' />
    <div class="gdev-error"></div>
</div>

Email Input

<div class="gdev-field-wrapper">
    <input type="email" Gdev-props='{"type":"email","name":"email", "provider": ["gmail", "outlook"] />
    <div class="gdev-error"></div>
</div>

Phone Input

<div class="gdev-field-wrapper">
    <input type="tel" Gdev-props='{"type":"tel","name":"phone", "country": ["cameroon", "nigeria"]}' />
    <div class="gdev-error"></div>
</div>

Number Input

<div class="gdev-field-wrapper">
    <input type="tel" name="number" Gdev-props='{"type":"number","name":"number","range":[20, 500], "multipleOf": 9}' />
    <div class="gdev-error"></div>
</div>

Documentation

For more detailed documentation and examples, visit our website.

License

This project is licensed under the MIT License.