Skip to content
Small utility for validating and generating Swiss national identification number.
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
dist
src
test
.babelrc
.eslintrc
.gitignore
.jshintignore
.jshintrc
LICENSE
README.md
bower.json
gulpfile.js
package.json

README.md

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

You can’t perform that action at this time.