@swan-io/shared-business 4.0.7 → 4.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Validator } from "react-ux-form";
|
|
2
2
|
import { AccountCountry } from "./templateTranslations";
|
|
3
3
|
export declare const isValidVatNumber: (maybeVat: string) => boolean;
|
|
4
|
+
export declare const isValidEmail: (maybeEmail: string) => boolean;
|
|
4
5
|
export declare const validateNullableRequired: Validator<string | undefined>;
|
|
5
6
|
export declare const validateRequired: Validator<string>;
|
|
6
7
|
export declare const validateBooleanRequired: Validator<boolean | undefined>;
|
package/src/utils/validation.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { noop } from "@swan-io/lake/src/utils/function";
|
|
2
2
|
import { match } from "ts-pattern";
|
|
3
3
|
import { t } from "./i18n";
|
|
4
|
+
const EMAIL_REGEX = /^[A-Z0-9_+.-]*[A-Z0-9_+-]@([A-Z0-9][A-Z0-9-]*\.)+[A-Z]{2,}$/i;
|
|
4
5
|
const VAT_NUMBER_REGEX = /^((AT)?U[0-9]{8}|(BE)?0[0-9]{9}|(BG)?[0-9]{9,10}|(CY)?[0-9]{8}L|(CZ)?[0-9]{8,10}|(DE)?[0-9]{9}|(DK)?[0-9]{8}|(EE)?[0-9]{9}|(EL|GR)?[0-9]{9}|(ES)?[0-9A-Z][0-9]{7}[0-9A-Z]|(FI)?[0-9]{8}|(FR)?[0-9A-Z]{2}[0-9]{9}|(GB)?([0-9]{9}([0-9]{3})?|[A-Z]{2}[0-9]{3})|(HU)?[0-9]{8}|(IE)?[0-9]S[0-9]{5}L|(IT)?[0-9]{11}|(LT)?([0-9]{9}|[0-9]{12})|(LU)?[0-9]{8}|(LV)?[0-9]{11}|(MT)?[0-9]{8}|(NL)?[0-9]{9}B[0-9]{2}|(PL)?[0-9]{10}|(PT)?[0-9]{9}|(RO)?[0-9]{2,10}|(SE)?[0-9]{12}|(SI)?[0-9]{8}|(SK)?[0-9]{10})$/;
|
|
5
6
|
// (AT)?U[0-9]{8} | # Austria
|
|
6
7
|
// (BE)?0[0-9]{9} | # Belgium
|
|
@@ -32,6 +33,9 @@ const VAT_NUMBER_REGEX = /^((AT)?U[0-9]{8}|(BE)?0[0-9]{9}|(BG)?[0-9]{9,10}|(CY)?
|
|
|
32
33
|
export const isValidVatNumber = (maybeVat) => {
|
|
33
34
|
return VAT_NUMBER_REGEX.test(maybeVat);
|
|
34
35
|
};
|
|
36
|
+
export const isValidEmail = (maybeEmail) => {
|
|
37
|
+
return EMAIL_REGEX.test(maybeEmail);
|
|
38
|
+
};
|
|
35
39
|
export const validateNullableRequired = value => {
|
|
36
40
|
if (value == null || !value) {
|
|
37
41
|
return t("error.requiredField");
|