iOS开发Textfield输入纯数字

- (BOOL)textField:(UITextField*)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString*)string

{


    NSCharacterSet*cs;


    cs = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789"] invertedSet];

    NSString*filtered = [[string componentsSeparatedByCharactersInSet:cs] componentsJoinedByString:@""];

    BOOL basicTest = [string isEqualToString:filtered];

    if(!basicTest) {

        

        UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"提示" message:@"请输入数字" preferredStyle:UIAlertControllerStyleAlert];

        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            

            

        }]];

        [self presentViewController:alert animated:YES completion:nil];


        return NO;

        

    }

    if (textField.text.length==6) {

        UIAlertController *alert=[UIAlertController alertControllerWithTitle:@"提示" message:@"密码为6位数字" preferredStyle:UIAlertControllerStyleAlert];

        [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            

            

        }]];

        [self presentViewController:alert animated:YES completion:nil];

        return NO;

    }

    return YES;

}

阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/mengwuqiang177/article/details/51548546
文章标签: iOS开发 uitextfield
上一篇iOSm转化Km
下一篇iOS开发关于上传图片后,图片发生旋转的处理
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭