Click here to Skip to main content
15,867,835 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello
I want to check either 10 digit mobile number is exited or not using Custom validation control can u guide or send any snippets
Posted
Comments
Richard C Bishop 28-Jun-12 10:01am    
Do you have to do it this way or are you just choosing to for fun?
Richard MacCutchan 28-Jun-12 10:30am    
What do you mean? Please try and compose a meaningful question.
Richard C Bishop 28-Jun-12 10:35am    
I was curious if the poster had to do it this way or was just wanting to. Based on that answer, I was going to suggest to just use the Regular Expression Validator with the US phone expression if they just needed a way to get it to work.
Richard MacCutchan 28-Jun-12 11:27am    
My question was directed at OP not at you.
Richard C Bishop 28-Jun-12 14:18pm    
My mistake.

Checking whether a number exists or not would not be a valid way of verifying the number. For instance, my former number exists but it is not in service. Even so, I do not believe there is one central way to verify that it "exists". However, if you are looking to be sure that the number put into the box is the customers' number, there are a couple ways of doing this.

The first way would be to use a service to verify the number for you. This is one example of that type of service (not a recommendation, just an example):

http://www.onverify.com/[^]

Another way that would be cheaper would be to do the verification yourself. If you are only verifying mobile phones, you could send a text to the phone with a generated number (just a short random string). Have the user type that string into your form to verify they were the ones that got the message. To do the actual sending of the text message, you could go cheap and email the text message email address of the phone (different for each carrier) or you could use a service such as Twilio[^] to send the message (at one cent per text inside the US). I do recommend Twilio. I've used them in the past and they are excellent, both in terms of their service as well as their customer support.
 
Share this answer
 
Hi,
You can use the below expression using regualr expression validator to validate the phone number

Quote:
var phoneFormat = /^\+?\d{1,3}(-|)?\d{3,5}(-|)?\d{1,10}$/;


Thanks
www.alacraft.com.au
 
Share this answer
 
Comments
Abhinav Gauniyal 16-Jul-14 23:24pm    
This would verify the actual number or the format of number?
Below is the code from Custom Validator from which you can validate mobile number :-


HTML
<html>
<head runat="server">
    <title>Custom Validator for Mobile</title>
    <script runat="server">
        void ValidateBtn_OnClick(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                lblOutput.Text = "Page is valid.";
            }
            else
            {
                lblOutput.Text = "Page is not valid!";
            }
        }
    </script>
    <script language="javascript">
        function ClientMobileValidate(source, arguments) {
            arguments.IsValid = false;
            if (!(isNaN(arguments.Value))) {
                arguments.IsValid = true;
            }
            if (arguments.Value.length == 10) {
                arguments.IsValid = true;
            }
            else {
                arguments.IsValid = false;
            }
        }

    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblOutput" runat="server" Text="Please enter 10 digit numeric Mobile Number"
            Font-Name="Verdana" Font-Size="10pt" />
        <asp:TextBox ID="Text1" runat="server" />
        &nbsp;&nbsp;
        <asp:CustomValidator ID="CustomValidator1" ControlToValidate="Text1" ClientValidationFunction="ClientMobileValidate"
            Display="Static" ErrorMessage="Please enter 10 digit numeric Mobile Number" ForeColor="green"
            Font-Name="verdana" Font-Size="10pt" runat="server" />
    </div>
    </form>
</body>
</html>



Below is the code of Javascript from which you can validate mobile number :-

Step 1:- Check txtMobile is blank.
Step 2:- Check txtMobile contains only numeric value.
Step3:-  Check txtMobile contains 10 digit only.

Javascript Code:

<script type="text/javascript">

function ValidateMobNumber(txtMobile) {
  var fld = document.getElementById(txtMobile);


  if (fld.value == "") {
  alert("You didn't enter a phone number.");
  fld.value = "";
  fld.focus();
  return false;
 }
  else if (isNaN(fld.value)) {
  alert("The phone number contains illegal characters.");
  fld.value = "";
  fld.focus();
  return false;
 }
 else if (!(fld.value.length == 10)) {
  alert("The phone number is the wrong length. \nPlease enter 10 digit mobile no.");
  fld.value = "";
  fld.focus();
  return false;
 }


}
</script>

HTML Code:

HTML
<input type="text" id="txtMobile" onblur="return ValidateMobNumber('txtMobile')" />




Hopt this code solves your problem. :) :) Happy Coding!!!!!!
 
Share this answer
 
v4
Script Function

XML
<script type="text/javascript">
        function Mobno() {
            var args = document.getElementById("txtMobno").value;
            if (args.length<10 || args.length>10 )
            {

                args.IsValid=false
            }
            else
            {

                args.IsValid=true
            }
        }
    </script>


Html Code



XML
<tr>
               <td>Custom Validator Check Mobile No(Must Be 10 Digit)</td>
               <td><asp:TextBox ID="txtMobno" runat="server"></asp:TextBox></td>
               <td>
                   <asp:CustomValidator ID="CustomValidator1" runat="server" ControlToValidate="txtMobno" ValidationGroup="Test"
                       ClientValidationFunction="Mobno"
                       ErrorMessage="MObile Number Must be 10 digit" ></asp:CustomValidator>
               </td>
           </tr>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900