vendredi 8 novembre 2019

Why I'm unable to validate textFields in login Button in Swift

I have given delegate to my all textfields but i am unable to validate if textfield is empty or not initially.. if i just put cursor in textfield, but without any text then i am able to check, then it says please enter PhoneNumber why?

if i didn't put cursor in textfield then access directly goes to else part, even all textfields are empty here is my code, please help me in the code.

func textFieldDidBeginEditing(_ textField: UITextField) {
    textField.text = ""
}
//MARK:- ButtonActions
@IBAction func loginButton(_ sender: Any) {

    if(userIdTextFielf.text == ""){
        AlertFun.ShowAlert(title: "", message: "Please enter PhoneNumber", in: self)
    }
    else if(passwordTextField.text == ""){
        AlertFun.ShowAlert(title: "", message: "Please enter Password", in: self)
    }
    else if(passwordTextField.text == "") && (userIdTextFielf.text == "") {
        AlertFun.ShowAlert(title: "", message: "Please enter PhoneNumber & Password", in: self)
    }
    else{
        logInService()
    }
}

please help me in the code.

Aucun commentaire:

Enregistrer un commentaire