Non-original, reproduced from http://blog.csdn.net/l2i2j2/article/details/51542028
If the last digit of the ID is x, enter 17 digits and auto-complete X
//TextField Proxy Method-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *)string { //String.Length is 0, indicating that there are no input characters, should be being deleted and should return yes. if(string. length = =0) { returnYES; } //length is the characters in the current input boxNsuinteger length = TextField.text.length +string. Length; //If there are other input boxes in the page, you need to make this decision if(TextField = =Self.idnumbertextfield) {//Str is the character in the current input boxNSString *str = [NSString stringWithFormat:@"%@%@", Textfield.text,string]; //when input to 17 digits, the last one is judged by the Thelastisx method is x if(Length = = -&&[self thelastisx:str]) { //if it is 17 bits, and the first 17 bits are calculated 18 bits x, Auto-complete, and return no, prohibit editing. Textfield.text = [NSString stringWithFormat:@"%@%@x", Textfield.text,string]; returnNO; } //returns less than or equal to 18 (up to 18 bits) if other conditions are true returnLength <= -; } returnYES;}//Judging if the last one is X-(BOOL) THELASTISX: (NSString *) IDNumber {Nsmutablearray*idarray =[Nsmutablearray array]; for(inti =0; I < -; i++) {Nsrange range= Nsmakerange (I,1); NSString*substring =[IDNumber Substringwithrange:range]; [IDArray addobject:substring]; } Nsarray*coefficientarray = [Nsarray arraywithobjects:@"7",@"9",@"Ten",@"5",@"8",@"4",@"2",@"1",@"6",@"3",@"7",@"9",@"Ten",@"5",@"8",@"4",@"2", nil]; intsum =0; for(inti =0; I < -; i++) { intcoefficient =[Coefficientarray[i] intvalue]; intID =[Idarray[i] intvalue]; Sum+ = coefficient *ID; } if(Sum% One==2)returnYES; Else returnNO;}
IOS ID The last one is X, enter 17 digits after auto-complete x (Turn)