@@ -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}
0 commit comments