Skip to content

Commit

Permalink
Update index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
0xbitx authored Aug 28, 2024
1 parent e0242ed commit df8bbe8
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
border: 1px solid #ddd;
width: 100%;
box-sizing: border-box;
max-width: 250px;
}

button {
Expand All @@ -78,6 +79,10 @@
font-size: 18px;
color: #000000;
}

.error {
color: red;
}
</style>
</head>
<body>
Expand All @@ -86,6 +91,7 @@ <h1>Sim Name Search</h1>
<form id="simForm">
<div class="form-group">
<input type="text" id="phoneNumber" placeholder="Enter phone number (09xx)" required>
<div id="error" class="error"></div>
</div>
<button type="submit">Check ISP</button>
</form>
Expand Down Expand Up @@ -182,11 +188,29 @@ <h1>Sim Name Search</h1>
'0944': 'Sun Cellular'
};

document.getElementById('phoneNumber').addEventListener('input', function () {
const input = this.value.replace(/\D/g, '');
if (input.length > 11) {
this.value = input.slice(0, 11);
} else {
this.value = input;
}
});

document.getElementById('simForm').addEventListener('submit', function (e) {
e.preventDefault();
const phoneNumber = document.getElementById('phoneNumber').value.replace(/\D/g, '');
const phoneNumber = document.getElementById('phoneNumber').value;
const errorDiv = document.getElementById('error');
let found = false;

if (phoneNumber.length !== 11) {
errorDiv.textContent = 'Phone number must be exactly 11 digits long.';
document.getElementById('result').innerHTML = '';
return;
} else {
errorDiv.textContent = '';
}

for (const prefix in prefixes) {
if (phoneNumber.startsWith(prefix)) {
document.getElementById('result').innerHTML = `Sim name for number <strong>${phoneNumber}</strong> is: <strong>${prefixes[prefix]}</strong>`;
Expand Down

0 comments on commit df8bbe8

Please sign in to comment.