Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to define maximum character length #309

Open
cemalsayin opened this issue Jan 17, 2020 · 1 comment
Open

how to define maximum character length #309

cemalsayin opened this issue Jan 17, 2020 · 1 comment

Comments

@cemalsayin
Copy link

Hi everyone, i'm creating payment view with credit card and i create SkyFloatingLabelTextField for card number you know card number text length 16. I've built card form with textFieldDidChange function (which puts "-" after every 4 character). I mean my SkyFloatingLabelTextField's max character should be 19. how can i define it?

@ashokTEZSOL
Copy link

you can use this method in "text field delegate"

func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
let maxLength = 19
let currentString: NSString = textField.text! as NSString
let newString: NSString =
currentString.replacingCharacters(in: range, with: string) as NSString
return newString.length <= maxLength
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants