Locate Mobile Number Using JavaScript in ASP.Net

Introduction

This article describes how to locate a mobile number in India in ASP.Net using JavaScript with state, service provider and service type.

Description

To create this application you need a JavaScript file that contains nearly all the mobile number data.

  • MoLocater.js
You can download it from the source code attached to this page.

Design

Add a textbox, a button and three div tags.

Now design your screen as in the following screen.

1.png

Or you can copy the following source code:

  1. <form id="form1" runat="server">  
  2.     <div>  
  3.         <table>  
  4.             <tr>  
  5.                 <td>  
  6.                     Mobile No. Locater  
  7.                 </td>  
  8.                 <td>  
  9.                     <asp:TextBox ID="txtMobileNo" runat="server" MaxLength="10"></asp:TextBox>  
  10.                 </td>  
  11.                 <td>  
  12.                     <asp:Button ID="Button1" runat="server" Text="Trace" OnClientClick="return GetPhnlocation();" />  
  13.                 </td>  
  14.             </tr>  
  15.             <tr>  
  16.                 <td colspan="3">  
  17.                     <div align="center" id="name" style="font-weight: bold;">  
  18.                     </div>  
  19.                     <div align="center" id="company" style="font-weight: bold;">  
  20.                     </div>  
  21.                     <div align="center" id="idno" style="font-weight: bold;">  
  22.                     </div>  
  23.                     <div align="center" id="info" style="font-weight: bold;">  
  24.                     </div>  
  25.                 </td>  
  26.             </tr>  
  27.         </table>  
  28.     </div>  
  29. </form> 

Next add the MoLocater.js JavaScript file to your website and add the link to the head tag:

  1. <script src="MoLocater.js" type="text/javascript"></script>
In the MoLocater.js file is the fuction GetPhnlocation(); see it to get the details.

I catch the first 4 digits of the Mobile number and match it to the 4 digit mobile pattern. Sample code is given below.

  1. function GetPhnlocation() {  
  2. var phone = document.getElementById('txtMobileNo');  
  3. var number = document.getElementById('name');  
  4. var state=document.getElementById('company');  
  5. var provider=document.getElementById('idno');  
  6. var service=document.getElementById('info');  
  7. var code = phone.value.slice(0, 4);  
  8. var re = /^[0-9]+$/;  
  9. if (phone.value != '' && re.test(phone.value)&& (phone.value.length==10) ) {  
  10.   if (code == "9000") {  
  11.       number.firstChild.nodeValue = 'Mobile No: ' + phone.value;  
  12.       state.firstChild.nodeValue = 'State: Andhra Pradesh';  
  13.       provider.firstChild.nodeValue = 'Service Provider: Airtel';  
  14.       service.firstChild.nodeValue = 'Service Type: GSM';  
  15.       return false;  
  16.      }  
  17.   
  18.   }  
  19. }

According to this you can also add your new pattern to this code.

Now build your application and enter a mobile number then click on the trace button. It will show all details of that mobile number.
2.png

For any modifications or problems please comment.

Thanks.


Similar Articles