-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathregexp.php
More file actions
66 lines (61 loc) · 1.65 KB
/
regexp.php
File metadata and controls
66 lines (61 loc) · 1.65 KB
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
<!DOCTYPE html>
<html>
<body>
<p>Click the button to diferenciate from a Variable and a Number!!</p>
<?php
$filename = 'regexp.txt';
$eachlines = file($filename, FILE_IGNORE_NEW_LINES);//create an array
echo '<select name="value" id="value">';
foreach($eachlines as $lines){
echo "<option>{$lines}</option>";
}
echo '</select>';
?>
<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("value").value;
//var strUser = e.options[e.selectedIndex].value;
//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>