Reputation: 601
I was looking for UIkeyboardtypenumberpad but used in an iPad example.
I mean, it is possible to create a class or view which simulated just a numeric keyboard, like iPhone??
i am using 4.1 sdk version.
i don't want to use special characters, just numbers and dot.
thanks!!
Upvotes: 4
Views: 1562
Reputation: 3907
add UITextFieldDelegate
in your header file (.h file)
txtfield_name.keyboardType=UIKeyboardTypeNumbersAndPunctuation;
txtfield_name.delegate=self;
then add this method
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string{
NSString *validRegEx =@"^[0-9.]*$"; //change this regular expression as your requirement
NSPredicate *regExPredicate =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", validRegEx];
BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:string];
if (myStringMatchesRegEx)
return YES;
else
return NO;
}
Upvotes: 8