Android edittext Mobile phone number format input xxx-xxxx-xxxx

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.