0% found this document useful (0 votes)
6 views1 page

Phone Number Validation Script

The document contains JavaScript code that adds an event listener to a button for phone number validation. When clicked, it fetches data from an API using a provided API key and displays the country, carrier, and line type if the number is valid, or an error message if invalid. It also handles errors related to fetching data or network issues.

Uploaded by

nagalohithb002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views1 page

Phone Number Validation Script

The document contains JavaScript code that adds an event listener to a button for phone number validation. When clicked, it fetches data from an API using a provided API key and displays the country, carrier, and line type if the number is valid, or an error message if invalid. It also handles errors related to fetching data or network issues.

Uploaded by

nagalohithb002
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

[Link]('lookupBtn').

addEventListener('click', function() {
const phone = [Link]('phoneInput').[Link]();
const apiKey = 'YOUR_API_KEY'; // Get from [Link]
const url = `[Link]
{phone}`;

fetch(url)
.then(response => [Link]())
.then(data => {
if ([Link]) {
[Link]('result').innerHTML = `
<p>Country: ${data.country_name}</p>
<p>Carrier: ${[Link]}</p>
<p>Line Type: ${data.line_type}</p>
`;
} else {
[Link]('result').innerHTML = '<p>Invalid phone
number.</p>';
}
})
.catch(error => {
[Link]('result').innerHTML = '<p>Error fetching
data. Check API key or network.</p>';
[Link](error);
});
});

You might also like