DOCTYPE html -- To change this license header choose License Headers i

 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
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
</head>
<body>
<input type="file" id="theFile" onChange="read(this)"/>
<script type="text/javascript">
function newIt(name, email, url){
var r = new Object();
r.name = name;
r.email = email;
r.url = url;
return r;
}
function isEmail(str){
var res = str.search(/^[a-z0-9]+((\.?[a-z0-9-_]+)*(\.?[a-z0-9]+)+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]+)$/i);
console.log(res);
console.log(str);
}
function isUrl(str){
}
function isName(str){
}
function read(ff)
{
if (window.File && window.FileReader && window.FileList && window.Blob) {
var cin = new FileReader();
cin.readAsText(ff.files[0]);
cin.onload = function (e){
var a = e.target.result.toString().split('\n\n');
for (var x in a){
var xx = a[x].split('\n');
var cnt = new Object();
var name, email, url;
cnt.email = 0;
cnt.name = 0;
cnt.url = 0;
for (var xxx in xx){
var str = xx[xxx];
if (isEmail(str)){
++cnt.email;
email = str;
}
else if (isUrl(str)){
++cnt.url;
url = str;
} else if (isName(str)){
++cnt.name;
name = str;
}
}
}
};
} else {
alert('The File APIs are not fully supported in this browser.');
}
}
</script>
</body>
</html>