Daddy
Daddy

Reputation: 9035

UIKeyboardTypeNumberPad - Show just numbes on iPad?

UIKeyboardTypeNumberPad doesn't display a number pad on the iPad. Instead, it shows the UIKeyboardTypeNumbersAndPunctuation keyboard.

Is there something I'm missing, or has this been removed from the iPad OS?

Thanks for your guidance!

Upvotes: 18

Views: 8986

Answers (3)

Hector
Hector

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

acecapades
acecapades

Reputation: 895

I know this question has been inactive for quite a while, but this might help somebody out there.

You can try implementing this one https://github.com/azu/NumericKeypad. The coder implemented his own number pad buy subclassing the UITextField

Upvotes: 2

Dustin Howett
Dustin Howett

Reputation: 1635

I believe that this is not currently supported in iPhoneOS 3.2 on the iPad

To quote the UITextInputTraits header file:

//
// UIKeyboardType
//
// Requests that a particular keyboard type be displayed when a text widget
// becomes first responder. 
// Note: Some keyboard/input methods types may not support every variant. 
// In such cases, the input method will make a best effort to find a close 
// match to the requested type (e.g. displaying UIKeyboardTypeNumbersAndPunctuation 
// type if UIKeyboardTypeNumberPad is not supported).
//

Upvotes: 14

Related Questions