-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented VAT validation support for english (en-GB) locale #1463
Implemented VAT validation support for english (en-GB) locale #1463
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1463 +/- ##
=======================================
Coverage 99.92% 99.92%
=======================================
Files 96 98 +2
Lines 1275 1340 +65
=======================================
+ Hits 1274 1339 +65
Misses 1 1
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your contrib! 🎉 Just 2 comment from me:
- Don't know if we could just go with country codes only for territorial stuff like VAT, so should this be
GB
orUK
? Just the way we've done for others like Passport... - see below.
src/lib/isVAT.js
Outdated
/^GB\d{3} \d{4} ([0-8][0-9]|9[0-6])$/, | ||
/^GB\d{9} \d{3}$/, | ||
/^GBGD[0-4][0-9]{2}$/, | ||
/^GBHA[5-9][0-9]{2}$/, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possible to make this one-line regex instead, to save on the matching loop later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep that works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the country codes, I'm cool going for ISO 3166-1 alpha-2 which would be GB
for the UK.
ping @profnandaa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to merge |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@CodingNagger -- qq, BTW, is VAT for GB different from that of UK? |
Hey @profnandaa GB is the ISO 3166-1 alpha-2 notation for the UK. |
Ok, thanks! |
README.md
Outdated
@@ -155,6 +155,7 @@ Validator | Description | |||
**isURL(str [, options])** | check if the string is an URL.<br/><br/>`options` is an object which defaults to `{ protocols: ['http','https','ftp'], require_tld: true, require_protocol: false, require_host: true, require_valid_protocol: true, allow_underscores: false, host_whitelist: false, host_blacklist: false, allow_trailing_dot: false, allow_protocol_relative_urls: false, disallow_auth: false }`.<br/><br/>require_protocol - if set as true isURL will return false if protocol is not present in the URL.<br/>require_valid_protocol - isURL will check if the URL's protocol is present in the protocols option.<br/>protocols - valid protocols can be modified with this option.<br/>require_host - if set as false isURL will not check if host is present in the URL.<br/>require_port - if set as true isURL will check if port is present in the URL.<br/>allow_protocol_relative_urls - if set as true protocol relative URLs will be allowed.<br/>validate_length - if set as false isURL will skip string length validation (2083 characters is IE max URL length). | |||
**isUUID(str [, version])** | check if the string is a UUID (version 3, 4 or 5). | |||
**isVariableWidth(str)** | check if the string contains a mixture of full and half-width chars. | |||
**isVAT(str, countryCode)** | checks that the string is a [valid VAT number](https://en.wikipedia.org/wiki/VAT_identification_number) if validation is available for the given country code matching [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please list the supported country codes so far in the README.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
I think that should be it, just that minor README fix and we should be good to go. |
I introduced the
isVAT
method based on a feature request spotted in #852. However, it feels like to big a piece to take all at once so I picked a locale which I need that validation for which is "en-GB".I purposefully excluded generated files as these seem to contain changes that are not currently checked in the main
master
branch so that this PR only contains my changes.Checklist