我想在文本字段中避免使用字符串和特殊字符,只使用数字键。

时间:2021-08-12 04:19:58

标签: ios swift

让字符集 = CharacterSet(charactersIn: "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@!#$%^&*")

@IBAction func actionManiusAns(sender:UIButton) { if txtFldOne.text == "" && txtFldTwo.text == "" && txtFldThree.text == ""{ alert(Title: "无输入", Message: "请输入一些内容") }

    else if txtFldOne.text == "" && txtFldTwo.text != "" && txtFldThree.text != ""{
        alert(Title: "第一个块中没有输入", Message: "请在第一个块中输入一些内容")
    }
    
    else if txtFldOne.text == "\(characterset)" && txtFldTwo.text == "\(characterset)" &&  txtFldThree.text == "\(characterset)": {
        alert(Title: "请使用数字", Message: "请输入数值输入")
    }
    
    else if txtFldOne.text != "" && txtFldTwo.text == "" &&  txtFldThree.text != "" {
        alert(Title: "第二个块中没有输入", Message: "请在第二个块中输入一些内容")
    }
    
    else if txtFldOne.text != "" && txtFldTwo.text == "" &&  txtFldThree.text == "" {
        alert(Title: "第二个块中没有输入", Message: "请在第二个块中输入一些内容")
    }
    
    else if txtFldOne.text != "" && txtFldTwo.text != "" &&  txtFldThree.text == "" {
        alert(Title: "第三个块中没有输入", Message: "请在第三个块中输入一些内容")
    }
    
    else {
        var firstNumber = Int(txtFldOne.text!)
        var secondNumber = Int(txtFldTwo.text!)
        var thirdNumber  = Int(txtFldThree.text!)
       var ans = Int(firstNumber! - secondNumber! - thirdNumber!)

        lblDisply.text = "\(ans)" }

}

0 个答案:

没有答案