定制 avalontechsv/idsv 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

avalontechsv/idsv

最新稳定版本:v1.0.0

Composer 安装命令:

composer require avalontechsv/idsv

包简介

Validate and format common identity numbers in El Salvador

README 文档

README

Esta documentación tambien está disponible en español.

Introduction

idSV is a tool for validation of common identity numbers in El Salvador, such as DUI and NIT.

Important notice

Since December 17th, 2021, DUIs are valid NITs for natural persons, so any DUI is a valid NIT. This means that you can use the same number for both validations in the context of a natural person (i.e. a person with a DUI).

Legal entities are not affected by this change, so you should still use the NIT validation for them.

There is also an option to override this functionality in the library when required.

Installation

You can use composer to install idSV in your project:

composer require avalontechsv/idSV

Usage

use avalontechsv\idSV\idSV;

$validator = new idSV();

// DUI validation
// Validate DUI in the format 00000000-0
var_dump($validator->isValidDUI('00000000-0')); // true
var_dump($validator->isValidDUI('00000000-1')); // false

// Validate DUI in the format 000000000
var_dump($validator->isValidDUI('000000000')); // true
var_dump($validator->isValidDUI('000000001')); // false

// The library will automatically trim the input.
// This is useful when you are validating user input.
var_dump($validator->isValidDUI(' 000000000 ')); // true

// NIT validation
// Validate NIT in the format 0000-000000-000-0
var_dump($validator->isValidNIT('0000-000000-000-0')); // true
var_dump($validator->isValidNIT('0000-000000-000-1')); // false

// Validate NIT in the format 0000000000000
var_dump($validator->isValidNIT('0000000000000')); // true
var_dump($validator->isValidNIT('0000000000001')); // false

// Also, you can validate NITs for natural persons
// in the DUI format.
var_dump($validator->isValidNIT('00000000-0')); // true
var_dump($validator->isValidNIT('00000000-1')); // false

// The library will automatically trim the input.
// This is useful when you are validating user input.
var_dump($validator->isValidNIT(' 0000000000000 ')); // true

// DUI and NIT can also be null
var_dump($validator->isValidDUI(null)); // false
var_dump($validator->isValidNIT(null)); // false

// DUI and NIT formatting

// Format DUI in the format 000000000
var_dump($validator->formatDUI('000000000')); // 00000000-0

// Shorter strings will be padded with zeros
var_dump($validator->formatDUI('00')); // 00000000-0

// If a DUI was already formatted, it will be returned as is
var_dump($validator->formatDUI('00000000-0')); // 00000000-0

// Invalid DUIs generate an exception
try { $validator->formatDUI('000000001'); } catch (\Exception $e) { echo 'Exception: ' . $e->getMessage(); } // Exception: Invalid DUI

// Format NIT in the format 0000000000000
var_dump($validator->formatNIT('00000000000000')); // 0000-000000-000-0

// Shorter strings will be padded with zeros
var_dump($validator->formatNIT('00')); // 0000-000000-000-0

// If a NIT was already formatted, it will be returned as is
var_dump($validator->formatNIT('0000-000000-000-0')); // 0000-000000-000-0

// Valid DUIs will be formatted as DUI in the NIT formatter by default
var_dump($validator->formatNIT('000000000')); // 00000000-0

// You can force the NIT formatter to disallow DUIs too
var_dump($validator->formatNIT('000000000', false)); // 0000-000000-000-0

// Padding is also applied to NITs
var_dump($validator->formatNIT('00', false)); // 0000-000000-000-0

// Invalid NITs generate an exception
try { $validator->formatNIT('0000000000001'); } catch (\Exception $e) { echo 'Exception: ' . $e->getMessage() . '\n';  } // Exception: Invalid NIT
## Testing
You can run the tests with PHPUnit:

```bash
./vendor/bin/phpunit

Or you can run the test script with composer:

composer test

Acknowledgements

  • gmelendezcr for the algorithm and gist to calculate the check digit in DUIs. Written in Javascript.
  • MauricioG for the algorithm to calculate the check digit in NITs. Written in Visual FoxPro.

License

This package is open-sourced software licensed under the GNU General Public License v3.0.

统计信息

  • 总下载量: 66
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2023-01-13

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固