当前位置:编程学习 > wap >>

控制键盘只能输入数字

 

 

#pragma mark  UITextFieldDelegate

 

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

    //  判断输入的是否为数字 (只能输入数字)

    NSString *validRegEx =@"^[0-9]*$";

    NSPredicate *regExPredicate =[NSPredicate predicateWithFormat:@"SELF MATCHES %@", validRegEx];

    BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:string];

    if (myStringMatchesRegEx)

        return YES;

    else

        return NO;

}

 

补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,