Click here to Skip to main content
15,886,578 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Mytextbox phone number is masked with this format (___)___-____

how to validate if enter less than 10 numbers using javascript
Posted
Comments
Philippe Mori 15-Oct-15 12:47pm    
If you want to support phone number in arbitrary countries, then don't use a mask that correspond to North America phone numbers. Use aomething generic that accept number and those characters: ( ) - and .
SathishRam 26-Oct-15 2:22am    
thank u all

Refer: http://forums.asp.net/post/2167678.aspx[^]

You can use MaskedEditValidator and define its ValidationExpression like:


ASP.NET
<asp:TextBox ID="TextBox2" runat="server" Width="130px" Height="16px" ValidationGroup="MKE" />

<ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender2"  runat="server"
            TargetControlID="TextBox2"
            Mask="999-999-9999"
            ClearMaskOnLostFocus="false"
            MessageValidatorTip="true"
            ></ajaxToolkit:MaskedEditExtender>

<ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator2"  runat="server"
            ControlExtender="MaskedEditExtender2"
            ControlToValidate="TextBox2"
            IsValidEmpty="False" ValidationExpression ="[0-9]{3}\-[0-9]{3}\-[0-9]{4}"
            EmptyValueMessage="input is required"
            InvalidValueMessage="input is invalid"
            Display="Dynamic"
            TooltipMessage="XXX-XXX-XXXX"
            EmptyValueBlurredText="Phone number should not be empty!"
            InvalidValueBlurredMessage="Please input the right phone number!"
            ValidationGroup="MKE" ></ajaxToolkit:MaskedEditValidator>



Hope this helps!
 
Share this answer
 
v2
While validating replace the brackets with blank and compare the length with 10.
 
Share this answer
 
my Solution
C#
function checkdate() {
                var InpDate = document.getElementById("<%=txtBirthdate.ClientID%>").value;
                 //var InpDate = document.getElementById(input).value;
                 var returnval = true;
                 if (InpDate != '' && InpDate != "__/__/____") {

                     var monthfield = InpDate.split("/")[0];
                     var dayfield = InpDate.split("/")[1];
                     var yearfield = InpDate.split("/")[2];
                     var dayobj = new Date(yearfield, monthfield - 1, dayfield);

                     if ((isNaN(dayobj.getMonth() + 1) == true) || (isNaN(dayobj.getDate()) == true) || (isNaN(dayobj.getFullYear())) == true) {
                         returnval = false;
                     }
                     if (yearfield < 1900) {
                         returnval = false;
                     }

                     if (dayobj.getDate() != dayfield) {
                         returnval = false;
                     }

                     if (dayobj.getMonth() + 1 != monthfield) {
                         returnval = false;
                     }
                 }
                 return returnval
             }
 
Share this answer
 
v2

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