diff --git a/content/docs/guides/helpers.md b/content/docs/guides/helpers.md index afb81e3..db54405 100644 --- a/content/docs/guides/helpers.md +++ b/content/docs/guides/helpers.md @@ -156,6 +156,7 @@ Alongside the VineJS helpers, you may also use the `vine.helpers` object to acce - `isLatLong` - `isMobilePhone` - `isPassportNumber` +- `isVAT` - `isPostalCode` - `isSlug` - `isDecimal` diff --git a/content/docs/types/string.md b/content/docs/types/string.md index de0bd55..7a50296 100644 --- a/content/docs/types/string.md +++ b/content/docs/types/string.md @@ -65,6 +65,7 @@ const messages = { mobile: 'The {{ field }} field must be a valid mobile phone number', passport: 'The {{ field }} field must be a valid passport number', postalCode: 'The {{ field }} field must be a valid postal code', + vat: 'The {{ field }} field must be a valid VAT number', } vine.messagesProvider = new SimpleMessagesProvider(messages) @@ -561,6 +562,31 @@ vine.object({ }) ``` +### vat +Ensure the field's value is formatted as a valid VAT number for a given or multiple country codes. + +```ts +vine.object({ + vat_number: vine + .string() + .vat({ countryCode: ['IN'] }) +}) +``` + +You may define a callback function to compute the options at runtime. + +```ts +vine.object({ + vat_number: vine + .string() + .vat((field) => { + return { + countryCode: [field.parent.country_code] + } + }) +}) +``` + ## Mutations Following is the list of mutations you can apply to a string value. As the name suggests, mutations normalize or change the input value and do not perform any validations.