javascript - Phone Number formatting with angular js issues in mobile browser -


have implemented function (for site working on) simultaneously format phone number while user entering number input field . front end has been coded using html/css angularjs(though not efficient in angular js). calling formatting function using ng-change directive. below function being called , formatting takes place when user enters 7th numeric digit.

     $scope.formatphnno =function(){         var elem = angular.element("#userid");         var userid=$scope.userid.replace(/[^\w\@\.]/g, '');         userid=  userid.replace(/\s/g,'');         var formattedid;          if(isnan(userid)){             $scope.userid=userid;             return;         }         else{            if(userid.length < 7 || userid.length>10){             $scope.userid=userid;         }         else if((userid.length > 6 && userid.length<11))  {             var ctnarray=[];             (var = 0, len = userid.length; < len; += 1) {                 if(ctnarray.length == 0){                     ctnarray[0]="(";                 }                 else if(ctnarray.length ==4){                     ctnarray[4]=")";                     ctnarray[5]=" ";                 }                 else if(ctnarray.length ==9){                     ctnarray[9]="-";                 }                 ctnarray.push(+userid.charat(i));                 formattedid=ctnarray.join().replace(/[,]/g, '');             }             elem[0].value = '';             elem[0].value = formattedid;          }          }     }; 

directly assigning formatted value model wasn't working in version of chrome changed value using element. function works fine on browser create no of issues on mobile browser. cursor placement issues happens when on launching app first time , enter values. if remove entered data in field , type again works fine. after formatting starts taking place i.e when user enter 7ts digit after the cross button on mobile keypad remove text stops functioning. there better way achieve functionality . didn't want use element directly model wasn't updating other way . needs on ng-change can't have function on blur that's requirement


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -