How to specify optional parts of the mask

2 posts, 0 answers
  1. BRiddle
    BRiddle avatar
    24 posts
    Member since:
    Sep 2010

    Posted 13 Jun 2014 Link to this post

    I'm using the UI for MVC MaskedTextBoxFor construct with phone numbers.  

    For basic areacode+number, it's working fine.   But I don't see anything in the documentation about how to add an additional optional extension number to the end - for a maximum form of "(000) 000-0000 x09999".   In your documentation I saw no predefined mask rules for optional parts of the mask.

    I see that I can do the validation part of this with a regex rule but don't see how to get the mask to automatically insert the " x" after the end of the "3333" part of the number in preparation of an option 1 to 5 number extension if and only if the user continues typing characters after typing the primary number "(000) 000-0000" part.

    I'm assuming that this should be able to be be done via a custom mask rule function, but didn't see any examples in your documentation involving optional pieces of content where fixed content like the " x" will be auto-added for the user.

  2. Georgi Krustev
    Georgi Krustev avatar
    3688 posts

    Posted 16 Jun 2014 Link to this post

    Hello Bob,

    As you pointed, MaskedTextBox does not have a built-in support for optional mask portion, because it does not clear the value on blur like other masked input widgets. You can define the mask like this
    .Mask("(000) 000-0000 09999")
    and the user will not lost the entered text if any of the required mask symbols ( '0' ) are omitted.
    If I am missing the point, could you please elaborate more on the desired behavior?

    Georgi Krustev

    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.

  3. UI for ASP.NET AJAX banner
Back to Top