Implement application to detect country by phone number.
<?php
// phpinfo();
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Sergey Drozdov - PhoneCheck test</title>
<link rel="stylesheet" href="bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<body>
<form>
<div class="jumbotron">
<h1 class="display-4">Phone Check</h1>
<p class="lead">This is a simple test project by <a href="http://sd.blackball.lv/job-change">Sergey Drozdov</a>.</p>
<a href="..">«« Back</a>
</div>
<div class="container">
<div class="form-row">
<div class="form-group col-4">
<input type="text" id="phoneNumber" class="form-control" placeholder="Enter phone number" />
</div>
<div class="form-group col">
<button type="button" id="checkNumber" class="btn btn-success">Check</button>
</div>
</div>
<div class="form-row">
<div class="col-4">
<div id="checkResult" class="alert alert-success" role="alert" style="visibility: hidden"></div>
</div>
</div>
</div>
</form>
<script type="text/javascript">
let phoneNumber = document.getElementById("phoneNumber");
let checkNumber = document.getElementById("checkNumber");
let resultBlock = document.getElementById("checkResult");
checkNumber.onclick = function() {
phoneNumber.value = phoneNumber.value.replace("+", "").replace(" ", "");
if (phoneNumber.value === '')
{
resultBlock.innerHTML = "Please enter phone number.";
resultBlock.setAttribute("class", "alert alert-warning");
resultBlock.setAttribute("style", "visibility: visible");
}
else
{
const request = new XMLHttpRequest();
request.open("GET", "core.php?number=" + phoneNumber.value, true);
request.send();
request.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
let result = JSON.parse(this.responseText);
if (result.status === 'success')
resultBlock.setAttribute("class", "alert alert-success");
else if (result.status === 'fail')
resultBlock.setAttribute("class", "alert alert-danger");
resultBlock.setAttribute("style", "visibility: visible");
resultBlock.innerHTML = result.message;
}
};
}
}
</script>
</body>
</html>