Skip to content

Commit 78320ef

Browse files
committed
Fix VAT numbers validators
1 parent b976d18 commit 78320ef

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>pl.nip24</groupId>
77
<artifactId>nip24-client</artifactId>
8-
<version>1.3.7</version>
8+
<version>1.3.8</version>
99

1010
<name>nip24-java-client</name>
1111
<description>NIP24 Service Client for Java</description>
@@ -64,7 +64,7 @@
6464
<plugin>
6565
<groupId>org.apache.maven.plugins</groupId>
6666
<artifactId>maven-javadoc-plugin</artifactId>
67-
<version>3.4.0</version>
67+
<version>3.4.1</version>
6868
<executions>
6969
<execution>
7070
<id>attach-javadocs</id>

src/main/java/pl/nip24/client/EUVAT.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,45 +33,45 @@ public class EUVAT {
3333

3434
/**
3535
* Konwertuje podany numer EU VAT do postaci znormalizowanej
36-
* @param nip numer EU VAT w dowolnym formacie
36+
* @param number numer EU VAT w dowolnym formacie
3737
* @return znormalizowany numer EU VAT
3838
*/
39-
public static String normalize(String nip)
39+
public static String normalize(String number)
4040
{
41-
if (nip == null || nip.length() == 0) {
41+
if (number == null || number.length() == 0) {
4242
return null;
4343
}
4444

45-
nip = nip.replaceAll("-", "");
46-
nip = nip.replaceAll(" ", "");
47-
nip = nip.trim().toUpperCase();
45+
number = number.replaceAll("-", "");
46+
number = number.replaceAll(" ", "");
47+
number = number.trim().toUpperCase();
4848

49-
if (!nip.matches("[A-Z]{2}[A-Z0-9]{2,12}")) {
49+
if (!number.matches("[A-Z]{2}[A-Z0-9+*]{2,12}")) {
5050
return null;
5151
}
5252

53-
return nip;
53+
return number;
5454
}
5555

5656
/**
5757
* Sprawdza poprawnoϾ numeru EU VAT
58-
* @param nip numer EU VAT
58+
* @param number numer EU VAT
5959
* @return true jeżeli podany numer jest prawidłowy
6060
*/
61-
public static boolean isValid(String nip)
61+
public static boolean isValid(String number)
6262
{
63-
if ((nip = normalize(nip)) == null) {
63+
if ((number = normalize(number)) == null) {
6464
return false;
6565
}
6666

67-
String cc = nip.substring(0, 2).toUpperCase();
68-
String num = nip.substring(2).toUpperCase();
67+
String cc = number.substring(0, 2).toUpperCase();
68+
String num = number.substring(2).toUpperCase();
6969

7070
if (!map.containsKey(cc)) {
7171
return false;
7272
}
7373

74-
if (!nip.matches(map.get(cc))) {
74+
if (!number.matches(map.get(cc))) {
7575
return false;
7676
}
7777

@@ -84,32 +84,32 @@ public static boolean isValid(String nip)
8484

8585
static {
8686
map.put("AT", "ATU\\d{8}");
87-
map.put("BE", "BE0\\d{9}");
87+
map.put("BE", "BE[0-1]{1}\\d{9}");
8888
map.put("BG", "BG\\d{9,10}");
8989
map.put("CY", "CY\\d{8}[A-Z]{1}");
9090
map.put("CZ", "CZ\\d{8,10}");
9191
map.put("DE", "DE\\d{9}");
9292
map.put("DK", "DK\\d{8}");
9393
map.put("EE", "EE\\d{9}");
9494
map.put("EL", "EL\\d{9}");
95-
map.put("ES", "ES[A-Z0-9]{9}");
95+
map.put("ES", "ES[A-Z0-9]{1}\\d{7}[A-Z0-9]{1}");
9696
map.put("FI", "FI\\d{8}");
9797
map.put("FR", "FR[A-Z0-9]{2}\\d{9}");
98-
map.put("GB", "GB[A-Z0-9]{5,12}");
9998
map.put("HR", "HR\\d{11}");
10099
map.put("HU", "HU\\d{8}");
101-
map.put("IE", "IE[A-Z0-9]{8,9}");
100+
map.put("IE", "IE[A-Z0-9+*]{8,9}");
102101
map.put("IT", "IT\\d{11}");
103102
map.put("LT", "LT\\d{9,12}");
104103
map.put("LU", "LU\\d{8}");
105104
map.put("LV", "LV\\d{11}");
106105
map.put("MT", "MT\\d{8}");
107-
map.put("NL", "NL\\d{9}B\\d{2}");
106+
map.put("NL", "NL[A-Z0-9+*]{12}");
108107
map.put("PL", "PL\\d{10}");
109108
map.put("PT", "PT\\d{9}");
110109
map.put("RO", "RO\\d{2,10}");
111110
map.put("SE", "SE\\d{12}");
112111
map.put("SI", "SI\\d{8}");
113112
map.put("SK", "SK\\d{10}");
113+
map.put("XI", "XI[A-Z0-9]{5,12}");
114114
}
115115
}

src/main/java/pl/nip24/client/NIP24Client.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
*/
5757
public class NIP24Client {
5858

59-
public final static String VERSION = "1.3.7";
59+
public final static String VERSION = "1.3.8";
6060

6161
public final static String PRODUCTION_URL = "https://www.nip24.pl/api";
6262
public final static String TEST_URL = "https://www.nip24.pl/api-test";

0 commit comments

Comments
 (0)