forked from mirjanadejonge/evTest
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vat.js
44 lines (38 loc) · 1.48 KB
/
vat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$(document).ready(function(){
$("#vat_number_check").click(function(){
var inputData = $("#vat_number").val();
var param = {
countryCode : inputData.substring(0,2),
vatNumber : inputData.substring(2)
}
$("#output_message").html("");
// check if the format is valid before ajax call
if (!isValid(param)){
$("#output_message").html("<b>Geen valide BTW nummer</b>");
return false;
}
$.ajax({
//url: "http://eduvisionopdracht.dev/VatCheck.php",
url: "VatCheck.php",
type: "GET",
data: param,
success: function(response){
result = jQuery.parseJSON(response);
if (result.error) {
$("#output_message").html("Er is een fout opgetreden: " + result.error);
}else if (result.valid){
$("#output_message").html("BTW nummer is geregistreerd voor " + result.name+', ' + result.address);
} else {
$("#output_message").html("BTW nummer is niet geregistreerd");
}
}
})
});
/**
* The countryCode input parameter must follow the pattern [A-Z]{2}
* The vatNumber input parameter must follow the [0-9A-Za-z\+\*\.]{2,12}
*/
function isValid(data){
return (data.countryCode.match('[A-Z]{2}') && data.vatNumber.match('[0-9A-Za-z\+\*\.]{2,12}'));
}
})