-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregexp.html
67 lines (59 loc) · 1.61 KB
/
regexp.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
<!DOCTYPE html>
<html>
<body>
<p>Click the button to diferenciate from a Variable and a Number!!</p>
<input id="textbox" type="text" />
<textarea rows="15" cols="50" id="myTextarea">
</textarea>
<input type="file" name="file" id="file">
<button onclick="isVariable()">What iam?</button>
<p id="res"></p>
<script>
document.getElementById('file').onchange = function(){
var file = this.files[0];
var reader = new FileReader();
reader.onload = function(progressEvent){
// Entire file
document.getElementById("myTextarea").value = this.result;
//console.log(this.result);
// By lines
var lines = this.result.split('\n');
for(var line = 0; line < lines.length; line++){
console.log(lines[line]);
}
};
reader.readAsText(file);
};
function isVariable() {
var str = document.getElementById("myTextarea").value;
var lines = srt.split('\n');
for(var line = 0; line < lines.length; line++){
var str = lines[line];
// var str = document.getElementById("myTextarea").value;
var patt1 = /^[0-9]+$/;
var patt2 = /^[a-zA-Z]+([a-zA-Z]+|[0-9]+)*$/;
var patt3 = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/;
var patt4 = /^https?:\/\/[\w\-]+(\.[\w\-]+)+[/#?]?.*$/;
if (str.match(patt2))
{
var result = "Im a Variable!";
}else if (str.match(patt1))
{
var result = "Im a Number!";
}else if (str.match(patt3))
{
var result = "Im a email!";
}else if (str.match(patt4))
{
var result = "Im a URL!";
}else
{
var result = "Not valid";
}
//document.getElementById("res").innerHTML = result;
console.log(result);
}
}
</script>
</body>
</html>