locked
TextBox Mask RRS feed

  • Question

  • User1372787940 posted

    I have a txtbox for phone that is masked for a phone number. I want to make it so that you have to enter all 10 numbers of the phone.

    <asp:TextBox ID="txtphn" runat="server" Width="130px" AutoComplete="off" CssClass="txtInfoBox"></asp:TextBox>
                    <asp:MaskedEditExtender runat="server" ID="meephn" Mask="(999) 999-9999" TargetControlID="txtphn"
                        ClearMaskOnLostFocus="False">
                    </asp:MaskedEditExtender>

    Thursday, May 21, 2015 8:48 AM

Answers

  • User281315223 posted

    I suppose that you could add the appropriate error properties to it and you could also use a RegularExpressionValidator to ensure that your content was in the proper format as well :

    <asp:MaskedEditExtender ID="meephn" 
                            runat="server"  
                            Mask="(999) 999-9999" 
                            TargetControlID="txtphn"
                            ClearMaskOnLostFocus="False"
                            EmptyValueMessage="A Phone Number is required"
                            InvalidValueMessage="Phone Number is invalid">
    </asp:MaskedEditExtender>
    <!-- Use a Regular Expression Validator as well to validate your content -->
    <asp:RegularExpressionValidator ID="PhoneRegexValidator"
                                    runat="server"
                                    ControlToValidate="txtphn"
                                    Display="Dynamic"
                                    ErrorMessage="Phone Number is invalid"
                                    SetFocusOnError="True"
                                    ValidationExpression="^\(\d{3}\) \d{3} \d{4}$">
    </asp:RegularExpressionValidator>
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 21, 2015 10:37 AM