First come:
Set the phone format operation only need to set EditText Addtextchangedlistener Listening, see the code below
/*edittext Input Monitoring*/Et_activity_up_login_phone.addtextchangedlistener (NewTextwatcher () {@Override Public voidBeforetextchanged (Charsequence charsequence,intIintI1,intI2) {} @Override Public voidOnTextChanged (Charsequence S,intStartintBefore,intcount) { if(s = =NULL|| S.length () = = 0)return; StringBuilder SB=NewStringBuilder (); for(inti = 0; I < s.length (); i++) { if(I! = 3 && I! = 8 && S.charat (i) = = '-') { Continue; } Else{sb.append (S.charat (i)); if((sb.length () = = 4 | | sb.length () = = 9) && Sb.charat (Sb.length ()-1)! = '-') {Sb.insert (Sb.length ()-1, '-'); } } } if(!sb.tostring (). Equals (S.tostring ())) { intindex = start + 1; if(Sb.charat (start) = = '-') { if(Before = = 0) {Index++; } Else{Index--; } } Else { if(Before = = 1) {Index--; }} et_activity_up_login_phone.settext (Sb.tostring ()); Et_activity_up_login_phone.setselection (index); }} @Override Public voidaftertextchanged (Editable Editable) {//get the phone number without--Endphone = Et_activity_up_login_phone.gettext (). toString (). Replace ("-", "" "); if(endphone.length () = = 11) {//if the last number is 11 digits//determine if the phone number is correct if(!Tool.isphonenum (Endphone)) {Toast.maketext (uploginactivity). This, "Please enter the correct phone number:" +Endphone, Toast.length_short). Show (); } Else { //change get captcha font colorTv_activity_up_login_djs.settextcolor (Color.parsecolor ("#64aaff"));//Highlight, you can clickDjstype =true;//set the verification code to a clickable stateTv_activity_up_login_djs.setclickable (true); } } } }); }
Android edittext Mobile phone number format input xxx-xxxx-xxxx