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

ms-validator

v3.1.1

Published

a vanilla js form validator

Downloads

18

Readme

ms Vanilla validator

  • a simple Javascript plugin developed in Vanilla Js to provide form validation
  • it support min, max, minleangh, maxlength, pattern and matching values validation
  • this plugin depend on HTML form attrs, it read form and inputs attr to generate the validators in runtime
  • it support Chrome, Firefox, Safari and Eadge browsers
  • it require Bootstrap v5.2.3 css only

Installation

$ npm install ms-validator

OR

$ yarn add ms-validator

Code Blocks

Form Tag require novalidate and name attr

<form class="p-5" method="get" novalidate name="example_form"></form>

Inputs require name and validators attr

<input 
  class="form-control inputForm" 
  type="text" 
  name="INPUT_NAME" 
  required="required"
  min="MIN_NUMBER" <!-- in case number input -->
  max="MAX_NUMBER" <!-- in case number input -->
  minlength="MIN_LENGTH" <!-- in case text input or textarea -->
  maxlength="MAX_LENGTH" <!-- in case text input or textarea -->
  pattern="REGEX" 
  <!-- in case text input or textareamatching input pass the matching input id  -->
  matchingId="MATCHING_INPUT_ID"  
/>

Javascript 

window.onload = function () {
    new Validate({
        form: document.forms.example_form,
        autoSubmit: true,
        callback: function (form) {
            console.log(form)
        }
    });
};

Matching Validation example

<div class="col-6">
    <div class="form-group">
        <label class="form-text" for="password"> Password </label>

        <input class="form-control inputForm" type="password" name="password" id="password"
            required="required" />

        <div class="valid-feedback error" id="password-error">
            <span id="password-error_required" class="d-none">password_error_req</span>
        </div>
    </div>
</div>
<div class="col-6">
    <div class="form-group">
        <label class="form-text" for="password">
            Confirm Password
        </label>

        <input class="form-control inputForm" type="password" name="confirm_password"
            id="confirm_password" required="required" matchingId="password" />

        <div class="valid-feedback error" id="confirm_password-error">
            <span id="confirm_password-error_required"
                class="d-none">confirm_password_error_req</span>
            <span id="confirm_password-error_matching"
                class="d-none">confirm_password_error_matching</span>
        </div>
    </div>
</div>

Textarea Example

<div class="col-12">
    <div class="form-group">
        <label class="form-text" for="text">
            Text
        </label>

        <textarea 
          class="form-control inputForm"  
          name="text" id="text"   
          required="required" 
          minlength="10"  
          maxlength="20"> 
        </textarea>

        <div class="valid-feedback error" id="text-error">
            <span id="text-error_required" class="d-none">text_error_req</span>
            <span id="text-error_minlength" class="d-none">text_error_minlength</span>
            <span id="text-error_maxlength" class="d-none">text_error_maxlength</span>
        </div>
    </div>
</div>

Group Example to validate at least one added value

<div class="row">
    <div class="col-12">Group 1</div>
    <div class="col-4 mb-3">
        <div class="form-group">
            <label class="form-text" for="option_1">option 1</label>
            <input class="form-control inputForm" type="text" name="option_1" id="option_1"
                group="1" minlength="5" />

            <div class="valid-feedback error" id="option_1-error">
                <span id="option_1-error_required" class="d-none">option_1_error_req</span>
                <span id="option_1-error_minlength" class="d-none">option_1_error_minlength</span>
            </div>
        </div>
    </div>

    <div class="col-4 mb-3">
        <div class="form-group">
            <label class="form-text" for="option_2">option 2</label>
            <input class="form-control inputForm" type="text" name="option_2" id="option_2"
                group="1" minlength="5" />

            <div class="valid-feedback error" id="option_2-error">
                <span id="option_2-error_required" class="d-none">option_2_error_req</span>
                <span id="option_2-error_minlength" class="d-none">option_2_error_minlength</span>
            </div>
        </div>
    </div>

    <div class="col-4 mb-3">
        <div class="form-group">
            <label class="form-text" for="option_3">option 3</label>
            <input class="form-control inputForm" type="text" name="option_3" id="option_3"
                group="1" minlength="5" />

            <div class="valid-feedback error" id="option_3-error">
                <span id="option_3-error_required" class="d-none">option_3_error_req</span>
                <span id="option_3-error_minlength" class="d-none">option_3_error_minlength</span>
            </div>
        </div>
    </div>

    <div class="valid-feedback error" id="group_1-error">
        <span id="group_1-error_required" class="d-none">add at least one of group_1values</span>
    </div>
</div>

| Paramater | Description | Type | | :---: | :---: | :---: | | form | the form selector | String | | autoSubmit | a boolean paramater to allow plugin from autosubmition | Boolean | | callback | a callback function to be excuted after validation is done to return validation results and allow you from sumit an ajax request in case autoSubmit is false | Function |

GITHUb

https://github.com/Moustafa2719/ms_vanilla_validator