Implemented VAT validation support for english (en-GB) locale#1463
Implemented VAT validation support for english (en-GB) locale#1463profnandaa merged 5 commits intovalidatorjs:masterfrom
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.
|
profnandaa
left a comment
There was a problem hiding this comment.
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
GBorUK? 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.
Possible to make this one-line regex instead, to save on the matching loop later?
There was a problem hiding this comment.
For the country codes, I'm cool going for ISO 3166-1 alpha-2 which would be GB for the UK.
|
ping @profnandaa |
|
looks good to merge |
|
@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
| **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.
Please list the supported country codes so far in the README.
|
I think that should be it, just that minor README fix and we should be good to go. |
I introduced the
isVATmethod 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
masterbranch so that this PR only contains my changes.Checklist