dni-js
Version:
Compute and validate a Spanish DNI/NIE number
59 lines (34 loc) • 1.44 kB
Markdown
Compute and validate a Spanish DNI/NIE numbers as described [here](http://www.interior.gob.es/web/servicios-al-ciudadano/dni/calculo-del-digito-de-control-del-nif-nie).
[](https://travis-ci.org/albertfdp/dni-js)
[](https://badge.fury.io/js/dni-js)
```
$ npm install dni-js
```
Validation is based on this [document](http://www.interior.gob.es/web/servicios-al-ciudadano/dni/calculo-del-digito-de-control-del-nif-nie).
```js
const dni = require('dni-js');
dni.isValid('12345678-Z'); // => true
```
Returns a DNI number with the control digit appended in the format `12345678-Z`. If the input is invalid,
returns `null`.
Returns a NIE number with the control digit appended in the format `X1234567-L`. If the input is invalid,
returns `null`.
Returns the control digit for the input.
Alias for `getControlDigit`.
Returns `true` or `false` by validating the input.
Given a string input, it returns a normalized valid DNI. When input is either not a string, or invalid, it returns null. For example:
```js
dni.normalize(' 12 34 56 7 8-z'); // 12345678-Z
```
MIT