https://github.com/singuerinc/spanish-car-plate
Spanish Car Plate validation
https://github.com/singuerinc/spanish-car-plate
auto car coche espana matricula patentes spain validacion validation
Last synced: 5 months ago
JSON representation
Spanish Car Plate validation
- Host: GitHub
- URL: https://github.com/singuerinc/spanish-car-plate
- Owner: singuerinc
- License: mit
- Created: 2019-02-15T19:48:12.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-09-04T23:22:26.000Z (over 4 years ago)
- Last Synced: 2024-11-21T03:56:01.443Z (5 months ago)
- Topics: auto, car, coche, espana, matricula, patentes, spain, validacion, validation
- Language: JavaScript
- Homepage:
- Size: 547 KB
- Stars: 7
- Watchers: 3
- Forks: 0
- Open Issues: 9
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
[](http://npm.im/spanish-car-plate)
[](https://app.codacy.com/app/nahuel.scotti/spanish-car-plate)
[](https://travis-ci.org/singuerinc/spanish-car-plate)
[](https://coveralls.io/github/singuerinc/spanish-car-plate?branch=master)
[](https://snyk.io/test/github/singuerinc/spanish-car-plate)
# Spanish Car Plate
Spanish car plate validation
_Validación de matriculas de coches en España_## Installation
```bash
npm i spanish-car-plate
```## Usage
### isValid()
```js
import { isValid, isOld } from "spanish-car-plate";isValid("1234BCD"); //=> true
isValid("1234 FGH"); //=> true
isValid("2345-JKL"); //=> true// note: old valid plates also returns true
isOld("A 0849 CS") === isValid("A 0849 CS"); //=> true
```### isOld()
```js
import { isOld } from "spanish-car-plate";// one-letter code
isOld("A 0849 CS"); //=> true// two-letter code
isOld("GI-1234-BL"); //=> true// two/three-letter special code (such as ET for army cars and DGP for police cars)
isOld("DGP 1234 BL"); //=> true
```### isSpecial()
Police, Air force, Army, Navy, etc. have special plates.
```js
import { isSpecial } from "spanish-car-plate";isSpecial("DGP 3874"); //=> true
isSpecial("CNP-5764"); //=> true
isSpecial("E8720"); //=> true
```### getCounter()
```js
import { getCounter } from "spanish-car-plate";getCounter("1234 BCD"); //=> "BCD"
getCounter("A-0849 CS"); //=> "CS"
```### getProvinceName()
It is possible to get the province's name from old plates
```js
import { getProvinceName } from "spanish-car-plate";getProvinceName("B 1234 BL"); //=> "Province of Barcelona"
getProvinceName("M-1234 BL"); //=> "Community of Madrid"
getProvinceName("SO 1234 BL"); //=> "Province of Soria"
```### getProvinceCode()
It is possible to get the province's code from old plates
```js
import { getProvinceCode } from "spanish-car-plate";getProvinceCode("B 1234 BL"); //=> "B"
getProvinceCode("M 1234 BL"); //=> "M"
getProvinceCode("SO-1234 BL"); //=> "SO"
```### getSpecialCode()
```js
import { getSpecialCode } from "spanish-car-plate";getSpecialCode("DGP1234"); //=> "DGP"
```### getSpecialName()
```js
import { getSpecialName } from "spanish-car-plate";getSpecialName("DGP1234"); //=> "Spanish Police"
getSpecialName("CME1234"); //=> "Corps of the Mossos d'Esquadra"
```### getNumber()
```js
import { getNumber } from "spanish-car-plate";getNumber("DGP0001"); //=> "0001"
getNumber("CME1234"); //=> "1234"
```### parse()
Get all the information about the plate
#### Parse new plate
```js
import { parse } from "spanish-car-plate";parse("1234 BCD");
``````json
{
"isSpecial": false,
"isOld": false,
"provinceCode": null,
"provinceName": null,
"number": 1234,
"counter": "BCD"
}
```#### Parse old plate
```js
parse("GI 2345 BC");
``````json
{
"isSpecial": false,
"isOld": true,
"provinceCode": "GI",
"provinceName": "Province of Girona",
"number": 2345,
"counter": "BC"
}
```## Demo
[https://spanish-car-plate.netlify.com/](https://spanish-car-plate.netlify.com/)
## Related
- [better-dni](https://github.com/singuerinc/better-dni) - Spanish dni/nif/nie validation
- [spain-phone](https://github.com/singuerinc/spain-phone) - Spanish phone number validation## Reference
[https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_Spain](https://en.wikipedia.org/wiki/Vehicle_registration_plates_of_Spain)