-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add backbonejs code, normalizephonenumber code
- Loading branch information
Showing
10 changed files
with
2,057 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head lang="en"> | ||
<meta charset="UTF-8"> | ||
<title>Backbonejs</title> | ||
<script src="../js/jquery.min.js"></script> | ||
<script src="../js/json2.js"></script> | ||
<script src="../js/underscore.js"></script> | ||
<script src="../js/backbone-min.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
(function($){ | ||
var ListView = Backbone.View.extend({ | ||
el: $("body"), | ||
initialize:function(){ | ||
_.bindAll(this, "render"); | ||
this.render(); | ||
}, | ||
render: function () { | ||
$(this.el).append("<ul><li>hello world</li></ul>"); | ||
} | ||
}); | ||
|
||
var listView = new ListView(); | ||
})(jQuery); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head lang="en"> | ||
<meta charset="UTF-8"> | ||
<title>Backbonejs</title> | ||
<script src="../js/jquery.min.js"></script> | ||
<script src="../js/json2.js"></script> | ||
<script src="../js/underscore.js"></script> | ||
<script src="../js/backbone-min.js"></script> | ||
</head> | ||
<body> | ||
<script> | ||
(function($){ | ||
var ListView = Backbone.View.extend({ | ||
el: $("body"), | ||
events:{ | ||
"click button#add":"addItem" | ||
}, | ||
initialize:function(){ | ||
_.bindAll(this, "render", "addItem"); | ||
|
||
this.counter = 0; | ||
this.render(); | ||
}, | ||
render:function(){ | ||
$(this.el).append("<button id='add'>Add list item</button>"); | ||
$(this.el).append("<ul></ul>"); | ||
}, | ||
addItem:function(){ | ||
this.counter++; | ||
$("ul", this.el).append("<li>hell world " + this.counter + "</li>"); | ||
} | ||
}); | ||
|
||
var listView = new ListView(); | ||
})(jQuery); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
0708806187 | ||
070-420 99 01 | ||
+46730521132 | ||
070-972 32 32 | ||
46709480296 | ||
073-0313337 | ||
070-49 65 808 | ||
0706 87 19 32 | ||
0705 - 607235 | ||
031151711 | ||
0000000000 | ||
0046703318174 | ||
0720492403 / 040-228566 | ||
+41791099035 | ||
0032473372281 | ||
0762300350, 0709621980 | ||
+4670-736 42 98 | ||
+46-76-794 86 99 | ||
0737-022476 | ||
076 791 92 24 | ||
+46 739 960725 | ||
5551234567 | ||
+46 706192202 | ||
+4670 647 24 61 | ||
+46 706192202 | ||
jensaue@hotmail.com | ||
7713584113 | ||
2154875421 | ||
+4746630117 | ||
+46 768723198 | ||
2342343244 | ||
5553454444 | ||
234534534535 | ||
345333455 | ||
535345345 | ||
3243242424 | ||
2342342424 | ||
4526227403 | ||
6035010806 | ||
5421548733 | ||
215487542154 | ||
112112112 | ||
98734743723 | ||
660822188449 | ||
7667677788 | ||
703224878 | ||
351916495332 | ||
919019872181 | ||
katt123 | ||
37057757529 | ||
+14155428249 | ||
kanokphan.nilsson22@gmail.com | ||
+32485388156 | ||
121313323432 | ||
639178169813 | ||
95521779854 | ||
44444444 | ||
333333333 | ||
200000000 | ||
99876666 | ||
91191074 | ||
95410926 | ||
777333333 | ||
1676150797 | ||
2356547658 | ||
3226752802 | ||
66623344545 | ||
602606206226 | ||
7777777777 | ||
700000000 | ||
602606206226 | ||
3847370500 | ||
8701619707 | ||
65589192195 | ||
95721544569 | ||
71762336654 | ||
+3547812381 | ||
2404764671 | ||
17508905900 | ||
68876287532 | ||
071 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
Order |original|result|explain|normalized | ||
1|0708806187|VALID|it's mobile phone number|+46708806187 | ||
2|070-420 99 01|VALID|it's mobile phone number|+46704209901 | ||
3|+46730521132|INVALID|invalid phone number format| | ||
4|070-972 32 32|VALID|it's mobile phone number|+46709723232 | ||
5|46709480296|INVALID|invalid phone number format| | ||
6|073-0313337|VALID|it's mobile phone number|+46730313337 | ||
7|070-49 65 808|VALID|it's mobile phone number|+46704965808 | ||
8|0706 87 19 32|VALID|it's mobile phone number|+46706871932 | ||
9|0705 - 607235|VALID|it's mobile phone number|+46705607235 | ||
10|031151711|INVALID|invalid phone number format| | ||
11|0000000000|INVALID|invalid phone number format| | ||
12|0046703318174|INVALID|invalid phone number format| | ||
13|0720492403 / 040-228566|INVALID|invalid phone number format| | ||
14|+41791099035|INVALID|invalid phone number format| | ||
15|0032473372281|INVALID|invalid phone number format| | ||
16|0762300350|VALID|it's mobile phone number|+46762300350 | ||
17|+4670-736 42 98|INVALID|invalid phone number format| | ||
18|+46-76-794 86 99|INVALID|invalid phone number format| | ||
19|0737-022476|VALID|it's mobile phone number|+46737022476 | ||
20|076 791 92 24|VALID|it's mobile phone number|+46767919224 | ||
21|+46 739 960725|INVALID|invalid phone number format| | ||
22|5551234567|INVALID|invalid phone number format| | ||
23|+46 706192202|INVALID|invalid phone number format| | ||
24|+4670 647 24 61|INVALID|invalid phone number format| | ||
25|+46 706192202|INVALID|invalid phone number format| | ||
26|jensaue@hotmail.com|INVALID|invalid phone number format| | ||
27|7713584113|INVALID|invalid phone number format| | ||
28|2154875421|INVALID|invalid phone number format| | ||
29|+4746630117|INVALID|invalid phone number format| | ||
30|+46 768723198|INVALID|invalid phone number format| | ||
31|2342343244|INVALID|invalid phone number format| | ||
32|5553454444|INVALID|invalid phone number format| | ||
33|234534534535|INVALID|invalid phone number format| | ||
34|345333455|INVALID|invalid phone number format| | ||
35|535345345|INVALID|invalid phone number format| | ||
36|3243242424|INVALID|invalid phone number format| | ||
37|2342342424|INVALID|invalid phone number format| | ||
38|4526227403|INVALID|invalid phone number format| | ||
39|6035010806|INVALID|invalid phone number format| | ||
40|5421548733|INVALID|invalid phone number format| | ||
41|215487542154|INVALID|invalid phone number format| | ||
42|112112112|INVALID|invalid phone number format| | ||
43|98734743723|INVALID|invalid phone number format| | ||
44|660822188449|INVALID|invalid phone number format| | ||
45|7667677788|INVALID|invalid phone number format| | ||
46|703224878|INVALID|invalid phone number format| | ||
47|351916495332|INVALID|invalid phone number format| | ||
48|919019872181|INVALID|invalid phone number format| | ||
49|katt123|INVALID|invalid phone number format| | ||
50|37057757529|INVALID|invalid phone number format| | ||
51|+14155428249|INVALID|invalid phone number format| | ||
52|kanokphan.nilsson22@gmail.com|INVALID|invalid phone number format| | ||
53|+32485388156|INVALID|invalid phone number format| | ||
54|121313323432|INVALID|invalid phone number format| | ||
55|639178169813|INVALID|invalid phone number format| | ||
56|95521779854|INVALID|invalid phone number format| | ||
57|44444444|INVALID|invalid phone number format| | ||
58|333333333|INVALID|invalid phone number format| | ||
59|200000000|INVALID|invalid phone number format| | ||
60|99876666|INVALID|invalid phone number format| | ||
61|91191074|INVALID|invalid phone number format| | ||
62|95410926|INVALID|invalid phone number format| | ||
63|777333333|INVALID|invalid phone number format| | ||
64|1676150797|INVALID|invalid phone number format| | ||
65|2356547658|INVALID|invalid phone number format| | ||
66|3226752802|INVALID|invalid phone number format| | ||
67|66623344545|INVALID|invalid phone number format| | ||
68|602606206226|INVALID|invalid phone number format| | ||
69|7777777777|INVALID|invalid phone number format| | ||
70|700000000|INVALID|invalid phone number format| | ||
71|602606206226|INVALID|invalid phone number format| | ||
72|3847370500|INVALID|invalid phone number format| | ||
73|8701619707|INVALID|invalid phone number format| | ||
74|65589192195|INVALID|invalid phone number format| | ||
75|95721544569|INVALID|invalid phone number format| | ||
76|71762336654|INVALID|invalid phone number format| | ||
77|+3547812381|INVALID|invalid phone number format| | ||
78|2404764671|INVALID|invalid phone number format| | ||
79|17508905900|INVALID|invalid phone number format| | ||
80|68876287532|INVALID|invalid phone number format| | ||
81|071|INVALID|invalid phone number format| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
function normalizeMobilePhoneNumber($phone, $isoCountryCode = "se") | ||
{ | ||
$phoneFormat = array( | ||
"se" => array( | ||
"countryCode" => "46", | ||
"phoneLength" => 9, | ||
"startCharacters" => array("07"), | ||
), | ||
); | ||
|
||
if (!array_key_exists(strtolower($isoCountryCode), $phoneFormat)) { | ||
throw new Exception("iso country code does not exists"); | ||
} | ||
|
||
$originalPhone = $phone; | ||
$countryCode = $phoneFormat[strtolower($isoCountryCode)]["countryCode"]; | ||
$phoneLength = $phoneFormat[strtolower($isoCountryCode)]["phoneLength"]; | ||
$startCharacters = $phoneFormat[strtolower($isoCountryCode)]["startCharacters"]; | ||
$phone = preg_replace("/[\+\-()\s]/", "", $phone); | ||
|
||
if ((strlen($phone) == $phoneLength + strlen($countryCode))) { | ||
$phone = preg_replace("/^$countryCode/", "", $phone); | ||
} | ||
|
||
$phoneIncludeZeroBeginning = $phone; | ||
$phone = preg_replace("/^0/", "", $phone); | ||
|
||
if ((preg_match("/[^0-9]+/", $phone)) || (strlen($phone) > $phoneLength + strlen($countryCode)) | ||
|| ((strlen($phone) == $phoneLength + strlen($countryCode)) && (!preg_match("/^$countryCode/", $phone))) | ||
|| (strlen($phone) < $phoneLength) || (strlen($phone) == 0) | ||
|| ((count($startCharacters) > 0) && (!preg_match("/^(" . join("|", $startCharacters) .")/", $phoneIncludeZeroBeginning))) | ||
) { | ||
return array( | ||
"original" => "$originalPhone", | ||
"result" => "INVALID", | ||
"explain" => "invalid phone number format", | ||
"normalized" => "", | ||
); | ||
}; | ||
|
||
return array( | ||
"original" => "$originalPhone", | ||
"result" => "VALID", | ||
"explain" => "it's mobile phone number", | ||
"normalized" => "+{$countryCode}{$phone}", | ||
); | ||
} | ||
|
||
$fileIn = fopen(realpath(dir(__FILE__)). DIRECTORY_SEPARATOR . "data/cellphones.txt", "r") or die("Unable to open file!");; | ||
$fileOut = fopen(realpath(dir(__FILE__)). DIRECTORY_SEPARATOR . "data/cellphones_validate.txt", "w") or die("Unable to open file!");; | ||
|
||
$outputDatas = array(); | ||
|
||
while(!feof($fileIn)){ | ||
$phone = fgetcsv($fileIn); | ||
$outputDatas[] = normalizeMobilePhoneNumber( $phone[0],"se"); | ||
} | ||
fclose($fileIn); | ||
|
||
$count = 0; | ||
fwrite($fileOut, "Order |original|result|explain|normalized\n"); | ||
foreach($outputDatas as $data){ | ||
$count++; | ||
$line = "{$count}|{$data["original"]}|{$data["result"]}|{$data["explain"]}|{$data["normalized"]}\n"; | ||
fwrite($fileOut, $line); | ||
} | ||
fclose($fileOut); |
Large diffs are not rendered by default.
Oops, something went wrong.
Empty file.
Oops, something went wrong.