IOS TextField Digital Keypad limited number of digits processing (especially for mobile phone login)

Source: Internet
Author: User

Hi~ everybody good, so long time not to meet with everybody, say ashamed, recently busy work, already long have not written a blog,

Let's share with you the processing of the digital keyboard limit in iOS---good, nonsense not much to say directly on the code

Did you encounter this problem when you landed with your mobile phone number? is one side want to enter a certain number of digits to limit input, but delete the time also to be able to delete, today small series encountered this problem, solve a half-day, finally solved it, good next to everyone to share

I believe we all know that the input box is used Uitextfield bar, the others do not say, to use TextField words to implement proxy method, the most important point is to set his keyboard mode for the numeric keypad

Txtfield.keyboardtype=uikeyboardtypenumberpad;

Then implement proxy method txtfield.delegate = self; implement proxy protocol

I'm sure you all know his proxy method. One of them is that every time a change is called

-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *) string{

if ([string isequaltostring:@ "]) return YES;

if (Textfield.tag = = Textfield_email_tag && textField.text.length >= 11) {

Phone number

return NO;

}else if (Textfield.tag = = Textfield_passwd_tag && textField.text.length >= 6) {

Password

return NO;

}else{

return YES;

}

}

The red is the key point, after a small series of tangled and observed for a long time, suddenly found that when the Click Delete button return string unexpectedly is @ "", is to seize this point to solve the problem, can limit the number of bits, but also to achieve the deletion-------well, it's time to rest. , we will continue to fight tomorrow-------

Limit digit handling for IOS TextField numeric keypad (ideal for mobile phone login)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.