-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathguid.html
81 lines (75 loc) · 2.08 KB
/
guid.html
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>SAPUID</title>
<style>
* {
box-sizing: border-box;
}
body {
margin: 50px 100px;
padding: 0;
}
input {
margin: 10px 0;
font-size: 16px;
}
button {
height 30px;
padding: 5px 20px;
}
</style>
</head>
<body style="">
<input id="sapguid" name="sapguid" style="width: 100%" placeholder="SAP-GUID">
<br />
<input id="normguid" name="normguid" style="width: 100%" placeholder="GUID">
<br />
<button onclick="convert()">Umwandeln</button>
<button onclick="clearFields()">Leeren</button>
<script>
function clearFields() {
var inputSapGuid = document.querySelector("#sapguid");
var inputNormGuid = document.querySelector("#normguid");
inputSapGuid.value = "";
inputNormGuid.value = "";
}
function convert() {
var inputSapGuid = document.querySelector("#sapguid");
var inputNormGuid = document.querySelector("#normguid");
if(inputSapGuid.value && !inputNormGuid.value) {
// SAP -> Normal
inputNormGuid.value = SapToNormal(inputSapGuid.value)
} else if(!inputSapGuid.value && inputNormGuid.value) {
// Normal -> SAP
inputSapGuid.value = normalToSap(inputNormGuid.value)
} else {
// Fehler
alert("Ein Feld muss leer sein.");
}
}
function normalToSap(guid) {
var result = guid.replace(/-/g,'');
return result.toUpperCase();
}
function SapToNormal(guid) {
// 8-4-4-4-12 - Format
var result = "";
if(guid.length >= 32) {
result = insertStringAtIndex(8, guid, "-");
result = insertStringAtIndex(13, result, "-");
result = insertStringAtIndex(18, result, "-");
result = insertStringAtIndex(23, result, "-");
} else {
alert("GUID ist zu kurz");
}
return result.toLowerCase();
}
function insertStringAtIndex(index, text, value) {
return text.slice(0, index) + value + text.slice(index);
}
</script>
</body>
</html>