This is a migrated thread and some comments may be shown as answers.

How to specify optional parts of the mask

1 Answer 426 Views
MaskedTextBox
This is a migrated thread and some comments may be shown as answers.
BRiddle
Top achievements
Rank 1
BRiddle asked on 13 Jun 2014, 06:26 PM
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.

Thanks!
-Bob

1 Answer, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 16 Jun 2014, 08:58 AM
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?

Regards,
Georgi Krustev
Telerik
 

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.

 
Tags
MaskedTextBox
Asked by
BRiddle
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
Share this question
or