I want to achieve following:
- Have a decimal keypad. Which means user will be able to enter Double values. (Needless to say "." will be limited one)
- Prevent "0" characters as the first characters. (i.e.: There should not be values like "003" "01" "000012" etc.)
- Limit the character count to 10.
- Only allow numbers. No Copy-Paste text values.
I am using decimal keypad. Below code handles first and third item above:
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let currentString: NSString = (textField.text ?? "") as NSString
let newString = currentString.replacingCharacters(in: range, with: string)
return newString.count <= 10
}
Thank you for your time.