Implementing Proxy methods
-(void) Textfieldedingchange: (uitextfield*) textfield{
if (Textfield.tag = = 4) {
nsstring* tempstring = [TextField getstringfilterspecialcharacter:@ ""];
if (tempstring.length = = 11) {
[TextField Resignfirstresponder];
}
}
}
-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *) string{
if (Textfield.tag = = 4) {
return [TextField Setphonenumberstyleshouldchangecharactersinrange:range replacementstring:string];
}
return YES;
}
which
/**
Set the display format for phone numbers (e.g.: 112 1189 9876)
@param range Length
@param a string input character
@return returns whether you can continue typing
*/
-(BOOL) Setphonenumberstyleshouldchangecharactersinrange: (nsrange) Range replacementstring: (NSString *) string{
Nsuinteger proposednewlength = textfield.text.length-range.length + string.length;
String.length>0 to perform the add operation at this time
if (string.length>0) {
Nsmutablestring *str=[nsmutablestring StringWithString:self.text];
while (self.text.length==3| | SELF.TEXT.LENGTH==8) {
if (self.text.length==3) {
[Str insertstring:@ "" atindex:3];
}
else if (self.text.length==8) {
[Str insertstring:@ "" atindex:8];
}
Self.text = [NSString stringwithstring:str];
}
}
String.length=0 The delete operation is now performed
else if (string.length==0) {
Nsmutablestring *str=[nsmutablestring StringWithString:self.text];
while (self.text.length==5| | self.text.length==10) {
if (self.text.length==5) {
[Str deletecharactersinrange:nsmakerange (4, 1)];
}
else if (self.text.length==10) {
[Str deletecharactersinrange:nsmakerange (9, 1)];
}
Self.text = [NSString stringwithstring:str];
}
NSLog (@ "%@", Textfield.text);
}
Limit the input length to 13. (Dividing line is also counted)
if (Self.text.length > 13) {
return no;//Limit length
}
return YES;
}
It is recommended to write to the TextField classification, which is convenient to call at any time, which realizes the format control of the mobile phone number.