首页 > 解决方案 > 使用天空浮动标签在文本字段上显示验证错误

问题描述

嗨,我skyfloatinglabel在我的应用程序中使用文本字段。我想在文本字段上显示错误。

我编写验证,如下所示它会显示错误,但它会移动到下一个屏幕如何控制它。

请找出以下错误:
fullnametxt.text == " "

func authendication()
    {
        let phoneNumber = phoneNumbertxt.text ?? ""
        let emailAddress = emailaddresstxt.text ?? ""
        let lastName = lastnametxt.text ?? ""
        let fullName = fullnametxt.text ?? ""

        // User Must Give The input for saving.
        if (phoneNumber.isEmpty) && (emailAddress.isEmpty) && (lastName.isEmpty) && (fullName.isEmpty)
        {
            phoneNumbertxt.errorMessage = "Enter email address."
            //self.showAlert("Alert!", "Fill All The Fields", "ok")
        }
        else if fullnametxt.text == " "
        {
            //self.showAlert("Alert!", "Must Fill The FullName", "ok")

            fullnametxt.errorMessage = "Full name"
            fullnametxt.errorColor = UIColor.appcolorlight
        }
}

标签: swiftvalidationuitextfield

解决方案


fullnametxt.text == " ". 在此检查" "中,这不是空字符串,它包含空格。因为空字符串是 this ""


推荐阅读