Jack BeNimble
Jack BeNimble

Reputation: 36643

How to limit iOS keyboard to numeric input

The question pretty much says it all. Is there any way to have the iOS/iPhone keyboard default to numeric input?

Upvotes: 31

Views: 28605

Answers (2)

Vette
Vette

Reputation: 541

Objective-C:

Default to Numbers (but include - and . if you need to allow decimal or negative numbers):

myTextField1.keyboardType=UIKeyboardTypeNumbersAndPunctuation;

Default to Numbers (#s only for integer values)

myTextField1.keyboardType=UIKeyboardTypeNumberPad;

Upvotes: 2

Ravi
Ravi

Reputation: 8309

Set the keyboardType property of the UITextField to UIKeyboardTypeDecimalPad.

Swift 3

yourUITextField.keyboardType = .decimalPad

Upvotes: 60

Related Questions