Way to Determine Mask Length

2 posts, 0 answers
  1. Matt
    Matt avatar
    87 posts
    Member since:
    Mar 2009

    Posted 21 Oct 2014 Link to this post

    Is there a method to determine the number of masked characters in a RadMaskedTextBox.Mask?  For example, if the mask is defined as "###-###-#### (US)" the number of masks is 10 (whereas the length of the mask would be 17).

    I've looked at the MaskParts collection, but don't see a simple way of determining the number of masks (vs. literals).

    Any help would be appreciated so I don't recreate the wheel!
  2. Konstantin Dikov
    Konstantin Dikov avatar
    2406 posts

    Posted 24 Oct 2014 Link to this post

    Hello Matt,

    In order for retrieving the length of the mask with and without the literals, you could use the get_valueWithPrompt() and get_valueWithPromptAndLiterals() methods:
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function pageLoad() {
                var maskedTextBox = $find("<%=RadMaskedTextBox1.ClientID%>");
                var withoutLiterals = maskedTextBox.get_valueWithPrompt().length;
                var withLiterals = maskedTextBox.get_valueWithPromptAndLiterals().length;
    <telerik:RadMaskedTextBox runat="server" ID="RadMaskedTextBox1" Mask="###-###-#### (US)"></telerik:RadMaskedTextBox>

    On server-side you could use the following:

    Best Regards,
    Konstantin Dikov

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

Back to Top