IOS ID The last one is X, enter 17 digits after auto-complete X

Source: Internet
Author: User


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)

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.