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

rich-validator

v2.0.2

Published

Client Side Form Validator

Downloads

84

Readme

Client Side From Validation

MIT License Made With Love

enter image description here

Introduction

why we provide this library

Validation is a very important to make sure the data is valid. However, if you leave the burden of data validation on the server alone, you will be wasting a lot of time and resources.

Because the server can only validate the data by sending a request, and this consumes a lot of time and resources, there must be a way to validate the data before sending the request to the server.

Why Vanilla Javascript

JavaScript is efficient for this task, so we relied on it in developing this library. We also wrote it in vanilla JavaScript so that it is compatible with your programming language, no matter which one you use to develop your system.

Installation

    npm i rich-validator

Usage

:warning: The package return bool (True - False) .

import { validator } from 'rich-validator';

let targetForm = document.querySelector('.targetForm');
let MainFormValidation = validator(targetForm); // Fire Validation
if (MainFormValidation) {
    // Do Something if no validation errors
} else {
    // Do Something form has validation errors
}

Features

  1. Required Input
  2. Email Input
  3. Mobile Number Validation
  4. Strong Password Validation
  5. force max length for input by default (255)

Validation Classes

:warning: The package has a global rule for any input in the targeted with [type='text'] to make max length 255 character.

if you want change the default max length you must add ths

<input type='text' rich-length='190' />

Validation Rules

    // For make any field has this class not empty
    querySelector('.required'); 
    // For make sure input has this class is a phone number and valid format
    querySelector('.phone-number');
    // For make sure input has this class is a strong password
    querySelector('.password');
    // For make sure input has this class is a valid email address
    querySelector('.validate-email');
    // For make sure uploaded file has a valid extension [jpg,jpeg,png,webp]
    querySelector('.validate-image');
    // For make sure uploaded file has a valid extension [text,txt]
    querySelector('.validate-text');
    // For make sure uploaded file has a valid extension [pdf]
    querySelector('.validate-pdf');
    // For make sure uploaded file has a valid extension [doc,docx]
    querySelector('.validate-doc');
    // Validate uploaded file size 
    querySelector('.validate-size');

and add size attribute

    <input type='file' data-size='4000' /> // 4 MB

Error Handling

You Must put your input in the parent div like this example

    <div>
        <input type='text' class='required' />
    </div>

if our library detect validation error for this input we append error message in the parent container like this example.

<div>
    <label for="slogan">Slogan</label>
    <input class="required" id="slogan" type="text" name="slogan" placeholder="Slogan" />
    <label class="validation-error">Slogan is required</label>
</div>

Customize error messages

    <!-- Customize Error Messages-->
    <!-- Required Validation Error -->
    <input 
    type='text' 
    data-required-error='Custom Required Error Message'
    class='required' />
    <!-- Phone Number Validation Error -->
    <input 
    type='text' 
    data-phone-error='Custom Phone Number Error Message'
    class='phone-number' />
    <!-- Email Validation Error -->
    <input 
    type='text' 
    data-email-error='Custom Email Error Message'
    class='validate-email' />
    <!-- Image Validation Error -->
    <input 
    type='file' 
    data-image-error='Custom Image Error Message'
    class='validate-image' />
    <!-- Text File Validation Error -->
    <input 
    type='file' 
    data-text-error='Custom Text File Error Message'
    class='validate-text' />
    <!-- PDF File Validation Error -->
    <input 
    type='file' 
    data-pdf-error='Custom PDF File Error Message'
    class='validate-pdf' />
    <!-- DOCS File Validation Error -->
    <input 
    type='file' 
    data-doc-error='Custom DOCS File Error Message'
    class='validate-pdf' />

Customize password validation error messages

    <!-- Custom Password Min Length Error Message -->
    <input 
    type='password' 
    data-password-error-min-length='Custom Password Min Length Error Message'
    class='password' />
    <!-- Custom Password Max Length Error Message -->
    <input 
    type='password' 
    data-password-error-max-length='Custom Password Max Length Error Message'
    class='password' />
    <!-- Custom Password Minimum One Character Lowercase Error Message -->
    <input 
    type='password' 
    data-password-error-lowercase='Custom Password Minimum One Character Lowercase Error Message'
    class='password' />
    <!-- Custom Password Minimum One Character uppercase Error Message -->
    <input 
    type='password' 
    data-password-error-uppercase='Custom Password Minimum One Character uppercase Error Message'
    class='password' />
    <!-- Custom Password Minimum One Character uppercase Error Message -->
    <input 
    type='password' 
    data-password-error-number='Custom Password Minimum One Number Error Message'
    class='password' />
    <!-- Custom Password Minimum One Spatial Character Error Message -->
    <input 
    type='password' 
    data-password-error-spatial='Custom Password Minimum One Spatial Character Error Message'
    class='password' />

Donation