Skip to content

Small utility for validating and generating Swiss national identification number.

License

Notifications You must be signed in to change notification settings

teaddict/swiss-ssn-avs-ahv

Repository files navigation

Swiss National Identification Number (AHV/AVS) or (SSN) validation and generation

npm version

  • A micro Javascript library for validating and generating Swiss National Identification Number.
  • Lightweight
  • No dependencies

Installation

NPM

npm install swiss-ssn

Bower

bower install swiss-ssn

From unpkg.com

<script src="https://unpkg.com/swiss-ssn/dist/swiss-ssn.min.js"></script>

Usage

ES6

import SwissSSN from "../swiss-ssn"
const isValid = SwissSSN.validate('756.9217.0769.85');
console.log(isValid);
//  result true

Using global namespace.

<script src="https://unpkg.com/swiss-ssn/swiss-ssn.min.js"></script>
<script>
  // This is valid SSN
  var isValid = SwissSSN.validate('756.9217.0769.85');
  console.log(isValid);
  //  result true
</script>

Examples

Validate SSN

//  This is valid Swiss SSN
console.log('valid ssn returns ' + SwissSSN.validate('756.9217.0769.85'));
//  'valid ssn returns true'

//  This is invalid Swiss SSN
console.log('invalid ssn returns ' + SwissSSN.validate('756.9217.0769.88'));
//  'invalid ssn returns false'

Generate SSN

//  generate a random SSN
var fakeSSN =  SwissSSN.generateSSN();
//  now validate it
console.log('Is ssn valid: ' + SwissSSN.validate(fakeSSN));

Functions

#validate(ssn)

  • Validates parameter given SSN. Returns true if SSN is valid, otherwise false

#generate()

  • Generates a random SSN. Returns formatted: '756.9217.0769.88'

Building

# Build a distributable, minified UMD library compatible with browsers and Node
npm run dist

# Run tests
npm run test

Test Online

check from my website

Changelog

1.0.1

  • Dependencies upgraded because of security problems.

1.0.0

  • Initial release

License

GPL License

About

Small utility for validating and generating Swiss national identification number.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published