Enter phone number to implement automatic 344 format

Source: Internet
Author: User

Use a space, if you use-to replace the space-ok

#define NUMBERS @ "0123456789"

1 //keyboard changes, control changes2-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *)string {3     4nscharacterset*CS;5CS =[[Nscharacterset charactersetwithcharactersinstring:numbers] invertedset];6nsstring*filtered = [[stringCOMPONENTSSEPARATEDBYCHARACTERSINSET:CS] Componentsjoinedbystring:@""];7BOOL basictest = [stringisequaltostring:filtered];8 9Nsinteger existedlength =textField.text.length;TenNsinteger selectedlength =range.length; OneNsinteger replacelength =string. Length; A      -     if(Existedlength-selectedlength + replacelength > -) { -         returnNO; the     } -  -      -     if(basictest) +     { -         if(TextField = =Phonetxtfield) +         { A  at             if([stringIsequaltostring:@""]){//Delete character -                 if((TextField.text.length-2) %4==0) && (TextField.text.length-2) %6!=0)) { -Textfield.text = [Textfield.text substringToIndex:textField.text.length-1]; -}Else if(TextField.text.length-2) %9==0){ -Textfield.text = [Textfield.text substringToIndex:textField.text.length-1]; -                 } in                 returnYES; -}Else { to                 if(textfield.text.length<5) { +                     if(TextField.text.length%4==0) { -Textfield.text = [NSString stringWithFormat:@"%@ ", Textfield.text]; the                     } *}Else{ $                     if(TextField.text.length%9==0) {Panax NotoginsengTextfield.text = [NSString stringWithFormat:@"%@ ", Textfield.text]; -                 } the                 } +                  A             } the             returnYES; +         } -     } $     Else $     { -         returnNO; -     } the      -     Wuyi     if(string. length = =0) { the          -         returnYES; Wu     } -      About      $     returnYES; -      -  -      A } +  the  - //keyboard off $-(void) Textfielddidendediting: (Uitextfield *) TextField the { the     if(TextField = = Phonetxtfield) && (textfield.text.length== -) ){ theNSLog (@"nine-bit input"); theNSString *all=[phonetxtfield.text Substringfromindex:1]; -          inNSString *first=[all Substringtoindex:3]; the          theNSString *pp=[all Substringfromindex:4]; About          theNSString *center=[pp Substringtoindex:4]; the          theNSString *last=[pp Substringfromindex:5]; +          -NSLog (@"aaaaaaaaaa=%@%@%@\n", first,center,last); the         BayiUserphone=[nsstring stringWithFormat:@"%@%@%@", First,center,last]; the  the     } -}

Enter phone number to implement automatic 344 format

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.