UItextField restrict user to enter number only IOS app on ipad -


i'm developing app ipad. i'm designing forgot password screen allow user enter password uitextfield. design, password allow numeric input. can set uitextfiled keyboardtype phonepad in iphone option seem not working ipad (ipad show full keyboard layout). how can achieve keyboard ipad app have number?

do have design own keyboard layout? appreciate. thanks!

the keyboard type not dictate sort of input textfield accepts, if use custom keyboard displays numbers, user can paste or use external hardware keyboard.

to that, need observe input, example, becoming uitextfielddelegate , then:
example in swift:

func textfield(_ textfield: uitextfield, shouldchangecharactersin range: nsrange, replacementstring string: string) -> bool{     // non decimal digit character set, better save property instead of creating each keyboard stroke     let non_digits = nscharacterset.decimaldigits.inverted     // find location non digits     let range = string.rangeofcharacter(from: non_digits)     if range == nil { // no non digits found, allow change         return true     }     return false // range valid, meaning non digits found } 

this prevent non digit character being added textfield.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -