I am developing iPhone application. I need to take input from user in textfield in fix format like xx-xxx-xxx. So I am not getting how to do this? Please suggest me the solution.
Asked
Active
Viewed 435 times
0
-
u need to visible the text 12-234-333 or xx-xxx-xxx format – Anbu.Karthik May 14 '14 at 08:55
-
In textfield placeholder , mention this format. User may catch the point as the format should to xx-xxx-xxx. – Ramdhas May 14 '14 at 08:58
-
I didn't get u,Actually when user start to input then input field should appear in this format like: - - – iOSHack May 14 '14 at 09:00
1 Answers
0
-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
if (range.location == 10) //this is calculate the overall string
{
return NO;
}
if ([string length] == 0) //string length is `0` hide the keyboard
{
return YES;
}
if ((range.location == 2) || (range.location == 6) ) //apply the `-` between the overall string
{
NSString *str = [NSString stringWithFormat:@"%@-",textField.text];
textField.text = str;
}
}

Anbu.Karthik
- 82,064
- 23
- 174
- 143