输入钱后面的小数点

-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    if ([string length]>0){
        //当前输入的字符
        unichar single=[string characterAtIndex:0];
        if ((single >='0' && single<='9')){
            //首字母不能为0
            if(textField.text.length==0||range.location==0){
                if (single =='0') {
                    [textField.text stringByReplacingCharactersInRange:range withString:@""];
                    return NO;
                }
            }else if (textField.text.length>7){
                return NO;
            }else{
                return YES;
            }
        }else{
            //不是 0-9 禁止输入
            return NO;
        }
    }
    return YES;
}

你可能感兴趣的:(输入钱后面的小数点)