Giter Club home page Giter Club logo

personnummer-php's Introduction

personnummer GitHub Workflow Status Packagist Version PHP from Packagist

Validate Swedish social security numbers.

Installation

composer require personnummer/personnummer

Methods

Static

Method Arguments Returns
parse string personnummer, [ array options* ] Instance
valid string personnummer, [ array options* ] bool

Instance

Method Arguments Returns
format bool longFormat string
getAge none int
isMale none bool
isFemale none bool
isCoordinationNumber none bool
Property Type Description
century string Century, two digits
year string Year, two digits
fullYear string Year, four digits
month string Month, two digits
day string Day, two digits
sep string Separator (-/+)
num string Suffix number, three digits
check string Luhn check digit, one digit

Errors

When a personnummer is invalid a PersonnummerException is thrown.

Options

Option Type Default Description
allowCoordinationNumber bool true Accept coordination numbers

Examples

Validation

use Personnummer\Personnummer;

Personnummer::valid(1212121212);
//=> true

Personnummer::valid('20121212-1212');
//=> true

Format

use Personnummer\Personnummer;

// Short format (YYMMDD-XXXX)
(new Personnummer(1212121212))->format();
//=> 121212-1212

// Short format for 100+ years old
(new Personnummer('191212121212'))->format();
//=> 121212+1212

// Long format (YYYYMMDDXXXX)
(new Personnummer('1212121212'))->format(true);
//=> 201212121212

Get Age

use Personnummer\Personnummer;

(new Personnummer('1212121212'))->getAge();
//=> 7

Get Sex

use Personnummer\Personnummer;

(new Personnummer('1212121212'))->isMale();
//=> true
(new Personnummer('1212121212'))->isFemale();
//=> false

See PersonnummerTest.php for more examples.

License

MIT

personnummer-php's People

Contributors

dependabot[bot] avatar frozzare avatar johannestegner avatar lantto avatar olssonm avatar rasmusbe avatar renovate-bot avatar renovate[bot] avatar superjoar avatar uxade avatar vinkla avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.