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 🙏

© 2026 – Pkg Stats / Ryan Hefner

validate-my-form

v1.0.4

Published

A form validator to JS

Readme

Validate my form

npm version

A form validator to validate input[required] fields;

Using Validate my form you can:

  • Validate a form;
  • Using default validation rules;
  • Create your own validation rules;

Installation

Using like a library
$ git clone https://github.com/rlazarini/validate-my-form.git
<body>
...
...
<script src="path/to/validate-my-form/index.js"></script>
</body>
Using like a module
$ npm install validate-my-form --save

Usage

Using like a module
var validateMyForm = require('validate-my-form');
validateMyForm._validateMyForm(form);

Examples

Basic Usage
<body>
	<form action="" id="form" novalidate>
		<input type="text">
		<!-- Validate only required fields -->
		<input type="text" required="required">
		<input type="email" required="required">
		<input type="number" required="required">
		<input type="password" required="required">
		<input type="submit" value="send">
	</form>
	<script>
		var form = document.getElementById('form');

		form.onsubmit = function(e) {
			e.preventDefault();
			validateMyForm._validateMyForm(form);
		}
	</script>
</body>
Create and validating a new type
<body>
	<form action="" id="form" novalidate>
		<input type="textwiththreespaces" required="required">
		<input type="submit" value="send">
	</form>
	<script>
		var form = document.getElementById('form')
		,	obj  = {
			'textwiththreespaces': /\w+\s{3}\w+/g
		};
		
		form.onsubmit = function(e) {
			e.preventDefault();
			validateMyForm._validateMyForm(form,obj);
		}
	</script>
</body>
Send a validate using attribute data-type

In this method, the input don't lose your properties. data-type="name" validate input[text] with rule text{space}text. You can create your own data-type and pass a object to validate then.

<body>
	<form action="" id="form" novalidate>
		<input type="text" data-type="name" required="required">
		<input type="text" data-type="myowndatatype" required="required">
		<input type="submit" value="send">
	</form>
	<script>
		var form = document.getElementById('form')
		,	obj  = {
			'myowndatatype': /^\d{2}[.]\d{3}[-]\d{3}[\/]\d{3}[-]\d{2}$/g
			// validate something like: 00.000-000/000-00
		}
		form.onsubmit = function(e) {
			e.preventDefault();
			validateMyForm._validateMyForm(form,obj);
		}
	</script>
</body>

Default Options to data-type

number  	## Validate a field with only numbers
cpf			## Validate a Brazil document
phone		## Validate a Brazilian phone number
zipcode		## Validate a Brazilian zipcode address
currency	## Validate a monetary value. By default, using R$, but you can pass a monetary symbol with attribute data-monetary (see more above)
name		## Validate a name, basically, they need two block of words: Like John Doe
creditcard	## Validate a Credit Card number with 16 digits with or without spaces
cvv			## Validate a Credit Card CVV number with 3 digits

The input[date] (or data-type[date], if you wish), has 2 another attributes you can use:

data-format  		## Pass the format of your date, by default use international date format (YYYYMMDD). Other options: DDMMYYYY; MMDDYYYY
data-gtCurrentDate	## Pass a boolean if you want the validated date to be greater than or equal to the current date

The data-type[currency], has 1 attribute you can use:

data-monetary		## You can pass a monetary symbol to your validation, by default: R$