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

@ashwinbande/validators

v1.0.7

Published

Different validators for Validating Codes

Downloads

37

Readme

Validators

Build Status codecov License: MIT npm version npm npm bundle size (scoped) Snyk Vulnerabilities for npm package version

Multiple set of validators for validating codes used in Indian system such as PAN, AADHAR, GSTIN etc.

Installation

NodeJS

    npm i @ashwinbande/validators
    // or
    yarn add @ashwinbande/validators

In your .js file add following code

    const isValid = require('@ashwinbande/validators')

CDN

Add <script src="https://cdn.jsdelivr.net/npm/@ashwinbande/validators@1/index.min.js"></script> at beginning of html file. then isValid will be available globally.

Usage

1. GSTIN (Goods and Service Tax Indentification Number):

validates => Input must be in format ##AAAAA####A#Z(#/A), and have length 15 and last char is Valid checksum.

const invalid = '09AAACT2727Q1ZA'
const valid = '09AAACT2727Q1ZU'
isValid.gstin(invalid) /* returns false */
isValid.gstin(valid)   /* returns true */

You can also calculate the checksum of a GSTIN by -

isValid.gstin.getValidDigit('09AAACT2727Q1ZA') /* return U */
isValid.gstin.getValidDigit('09AAACT2727Q1Z')  /* return U */

Note that only first 14 characters are required and next are ignored.

2. PAN (Permanent Account Number):

validates => Input must be in format AAAAA####A, and have length 10 and fourth character must be either A, B, C, F, G, H, L, J, P, T, E.

isValid.pan('AAACT2727Q')  /* returns true  */
isValid.pan('11ACT2727Q')  /* returns false */

You can also obtain PAN holder type by -

isValid.pan.holder('AAACT2727Q')  /* returns 'Company'  */

possible values are -

A: Association Of Persons (AOP),
B: Body Of Individuals (BOI),
C: Company,
F: Firm,
G: Government,
H: Hindu Undivided Family (HUF),
L: Local Authority,
J: Artificial Juridical Person,
P: Individual (Proprietor),
T: Trust (AOP),
E: Limited Liability Partnership (LLP),

3. TAN (Tax Deduction and Collection Account Number):

validates => Input must be in format AAAA#####A, and have length 10 and last char is Valid checksum.

const invalid = 'MUMT07207A'
const valid = 'MUMT07207E'
isValid.tan(invalid) /* returns false */
isValid.tan(valid)   /* returns true  */

4. AADHAR (Issued by - Unique Identification Authority of India):

validates => Input must be in format ############, and have length 12 and last char is Valid checksum.

const invalid = '499128665246'
const valid =   '499118665246'
isValid.aadhar(invalid) /* returns false */
isValid.aadhar(valid)   /* returns true  */

You can also calculate the checksum of a AADHAR by -

isValid.aadhar.getValidDigit('49911866524') /* return 6 */

5. IMEI (International Mobile Equipment Identity):

validates => Input must be in format ###############, and have length 15 and last digit is Valid checksum.

const invalid = '357917092311929'
const valid =   '357917052311929'
isValid.imei(invalid) /* returns false */
isValid.imei(valid)   /* returns true  */

6. Credit / Debit Card:

validates => Input must be in format ##############(##), and have length 14 or 15 or 16 and last digit is Valid checksum.

const invalid = '5103720017095346'
const valid =   '5103720017096346'
isValid.card(invalid) /* returns false */
isValid.card(valid)   /* returns true  */

7. IFSC (Indian Financial System Code):

validates => Input must be in format AAAA#######, and have length 11.

const invalid = 'SBIN000I234'
const valid =   'SBIN0001234'
isValid.ifsc(invalid) /* returns false */
isValid.ifsc(valid)   /* returns true  */

8. ESIC Number (Employees State Insurance Corporation Number):

validates => Input must be in format #################, and have length 17.

const invalid = '3100123456A000001'
const valid =   '31001234560000001'
isValid.esic(invalid) /* returns false */
isValid.esic(valid)   /* returns true  */

9. UAN (Universal Account Number):

validates => Input must be in format ############, and have length 12.

const invalid = '11122Z333444'
const valid =   '111222333444'
isValid.esic(invalid) /* returns false */
isValid.esic(valid)   /* returns true  */

10. Mobile Number:

validates => Input must be in format ##########, and have length 10.

const invalid = '99887766A5'
const valid =   '9988776655'
isValid.mobile(invalid) /* returns false */
isValid.mobile(valid)   /* returns true  */

11. PIN CODE (Postal Identification Number):

validates => Input must be in format ######, and have length 6.

const invalid = '44520'
const valid =   '445206'
isValid.pinCode(invalid) /* returns false */
isValid.pinCode(valid)   /* returns true  */

12. HSN (Harmonized System Nomenclature):

validates => Input must be in format ##(##)(##)(##), and have length 2 or 4 or 6 or 8.

hsn('4')        /* returns false */
hsn('445')      /* returns false */
hsn('44556')    /* returns false */
hsn('445566A4') /* returns false */
hsn('44')       /* returns true  */
hsn('4455')     /* returns true  */
hsn('445566')   /* returns true  */
hsn('44556634') /* returns true  */

13. SAC (Services Accounting Code):

validates => Input must be in format ########, and have length 8.

hsn('445566A4') /* returns false */
hsn('44556634') /* returns true  */

For Feature requests and Error reporting:

create an issue on github repository or contact directly to [email protected]

**Don't Forget to add a star to github repo. Please provide your comments, suggest improvements and other codes which are not covered in this package.