Custom widget to masking text


I need to create a masking custom widget. My use case is as follows.

The text in the textbox should be masked based on pattern specified. The initial use case is, if the number is "68966486" then the widget should render "****6486". I wanted it to extend it so that it could mask based on the regular expression to make it more generic.

In order to achieve it, I tried the following so far.