Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 28-Jun-12 3:58am
kingsa1.4K
Comments
richcb at 28-Jun-12 10:01am
   
Do you have to do it this way or are you just choosing to for fun?
Richard MacCutchan at 28-Jun-12 10:30am
   
What do you mean? Please try and compose a meaningful question.
richcb at 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 at 28-Jun-12 11:27am
   
My question was directed at OP not at you.
richcb at 28-Jun-12 14:18pm
   
My mistake.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
Comments
Abhinav Gauniyal at 16-Jul-14 23:24pm
   
This would verify the actual number or the format of number?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Below is the code from Custom Validator from which you can validate mobile number :-
 

<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:
 
<input type="text" id="txtMobile" onblur="return ValidateMobNumber('txtMobile')" />
 

 
Hopt this code solves your problem. Smile | :) Smile | :) Happy Coding!!!!!!
  Permalink  
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

Script Function

<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

 

<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>
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 344
1 Sergey Alexandrovich Kryukov 337
2 CPallini 180
3 Abdul Samad KP 145
4 Richard MacCutchan 110
0 OriginalGriff 6,329
1 Sergey Alexandrovich Kryukov 5,700
2 CPallini 4,940
3 George Jonsson 3,469
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 16 Jul 2014
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100