Search code examples
javascriptangularjsangular-ui-bootstrapmaskinput-field

Mask integer in Read-Only input field in AngularJs?


I have 2 pages.In first page i will fill my mobile number.Then,navigating to the second page I will show the mobile number in read only.In that i need to show the number like xxxxxx1234. If user clicks the edit button then,it should show all the numbers like 8790561234.

I couldn't get the masking for read only field.?Any suggestions??


Solution

  • With slice and replace, you can achieve what you want:

    var orig = scope.ngModel;
        var edited = orig;
        scope.ngModel = edited.slice(4).replace(/\d/g, 'x') + edited.slice(-4);
    

    Check out this similar Plunker.