-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (42 loc) · 2.07 KB
/
index.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
let input = document.getElementById("data");
input.addEventListener("keypress", (e) =>{
if(e.key =="Enter"){
format();
copy();
}
});
function format(){
var data = document.getElementById("data").value.replace(" ","").replace(" ","").replace(" ","");
var resultData = document.getElementById("data");
var result = document.getElementById("result");
if(data.length == 11){
resultData.value = data.substring(0,3)+"."+data.substring(3,6)+"."+data.substring(6,9)+"-"+data.substring(9,11);
result.innerHTML = data.substring(0,3)+"."+data.substring(3,6)+"."+data.substring(6,9)+"-"+data.substring(9,11);
console.log(data.substring(0,3)+"."+data.substring(3,6)+"."+data.substring(6,9)+"-"+data.substring(9,11));
}
else if(data.length == 14 ){
if(data.substring(8,11) == "000" ){
resultData.value = `${data.substring(0,2)}.${data.substring(2,5)}.${data.substring(5,8)}/${data.substring(8,12)}-${data.substring(12,14)}`;
result.innerHTML = `${data.substring(0,2)}.${data.substring(2,5)}.${data.substring(5,8)}/${data.substring(8,12)}-${data.substring(12,14)}`;
} else{
data.replace(".","").replace(".","").replace("-",""); data.replace(".","").replace(".","").replace("-","");
result.innerHTML = data.replace(".","").replace(".","").replace("-","");
resultData.value = data.replace(".","").replace(".","").replace("-","");
}
}
//else if(data.length == 14 && data.substring(8,11) == "000" ){
else if (data.length == 18){
resultData.value = data.replace(".",'').replace(".","").replace("/","").replace("-","");
result.innerHTML = data.replace(".",'').replace(".","").replace("/","").replace("-","");
}
else {
result.innerHTML = data.toLowerCase();
resultData.value = data.toLowerCase();
console.log(document.getElementById("result").value)
}
}
function copy(){
var result = document.getElementById("data");
result.select();
navigator.clipboard.writeText(result.value);
}