Code Monkey home page Code Monkey logo

laravel-grvatid-validator's Introduction

Greek VAT ID Validator for Laravel

The Greek VAT ID validator checks if a number is POTENTIALLY valid in Greek VAT ID Registry.

Validator does NOT check if VAT ID does actually belong to a person or a company, it checks only if it obeys the algorithm of a valid Greek VAT ID:

1. VAT ID = 090000045
2. Calculate sum of 0*2^8+9*2^7+0*2^6+0*2^5+0*2^4+0*2^3+0*2^2+4*2^1 = 1160
3. Calculate mod11 = 1160 % 11 = 5
4. Calculate mod10 = 5 % 10 = 5
5. mod10 (5) is equal to 5 (last digit), so VAT ID is VALID
1. VAT ID = 123456789
2. Calculate sum of 1*2^8+2*2^7+3*2^6+4*2^5+5*2^4+6*2^3+7*2^2+8*2^1 = 1004
3. Calculate mod11 = 1004 % 11 = 3
4. Calculate mod10 = 3 % 10 = 3
5. mod10 (3) is not equal to 9 (last digit), so VAT ID is INVALID

Installation

Install the package using Composer:

composer require liagkos/laravel-grvatid-validator

Laravel's service provider discovery will automatically configure the Grvatval service provider for you.

Using the grvatval validator

After installation, the grvatval validator will be available for use directly in your validation rules.

'vatid' => 'grvatval',

Within the context of a registration form, it would look like this:

return Validator::make($data, [
    'name' => 'required',
    'email' => 'required|string|email',
    'password' => 'required',
    'vatid' => 'required|grvatval'
]);

Using the Rule Object

Alternatively, you can use the Liagkos\Grvatval\Grvatval Validation Rule Object instead of the grvatval alias if you prefer:

return Validator::make($data, [
    'name' => 'required',
    'email' => 'required|string|email',
    'password' => 'required',
    'vatid' => ['required', new \Liagkos\Grvatval\Grvatval],
]);

Validation message

You will need to assign your own validation message within the resources/lang/*/validation.php file(s). Both the Rule object and the grvatval validator alias refer to the validation string validation.grvatval.

Testing

Just run the the test in tests directory. I use the orchestra/testbench along with PHPUnit.

Credits

Since I'm quite new in all Laravel stuff, I got the idea from Stephen Rees-Carten and his own valorin/pwned-validator validator, from whom I used some code and README.md stuff, modified accordingly to make this validator. Thank you Stephen, live long and propsper!

laravel-grvatid-validator's People

Contributors

liagkos 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.