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