When the user enters the content UITextField and detects the input and responds to the events on the page according to the user's input, in this case, the user input mobile phone number is detected in real time, and when the number of digits reaches 11 digits and the format of the mobile number is satisfied, the button becomes available.
The code is as follows:
First declare TextField and add the following method:
- (BOOL) TextField: (uitextfield *) Textfield shouldchangecharactersinrange: (Nsrange) range Replacementstring: (nsstring *) string { nsstring *checkstring; if (range.location == 11) { return NO; }else{ if (![ string isequaltostring:@ ""]) { checkString=[self.textfield.text stringByAppendingString:string]; }else{ checkString=[checkString stringByDeletingLastPathComponent]; } if ([Self ismobilenumber: CheckString]) { nslog (@ "number satisfies"); }else{ nslog (@ "number not satisfied"); } return yes; } }
Mobile phone number detection use the following code:
-(BOOL) Ismobilenumber: (NSString *) mobilenum {NSString * MOBILE = @ "^ ((13[0-9]) | ( 14[^4,\\D]) | (15[^4,\\d]) | (18[0-9])) \\d{8}$|^1 (7[0-9]) \\d{8}$ "; Nspredicate *regextestmobile = [Nspredicate predicatewithformat:@ "Self MATCHES%@", MOBILE]; if ([regextestmobile evaluatewithobject:mobilenum] = = yes) {return yes; }else{return NO; } }
Original link: http://blog.yourtion.com/ios-realtime-uitextfield-contect.html
iOS real-time detection of Uitextfield content