Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

P2022-1321 Register screen functionality (validation) #27

Merged
merged 2 commits into from
Mar 7, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
P2022-1321 Register screen functionality (validation)
  • Loading branch information
AdrianPat committed Mar 6, 2022
commit 3f81c818f5fde19cb29b0a593de4d61f6af8bb11
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,69 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.EditText
import com.intive.patronage22.intivi.MainActivity
import com.intive.patronage22.intivi.R
import com.intive.patronage22.intivi.databinding.FragmentSignUpBinding
import java.util.regex.Pattern

class SignUpFragment : Fragment() {

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View
{
): View {
val bind = FragmentSignUpBinding.inflate(layoutInflater)

bind.SignUpButton.setOnClickListener{
val intent = Intent(this.requireContext(), MainActivity::class.java)
startActivity(intent)
bind.SignUpButton.setOnClickListener {
if (isEmailOK() and isPasswordOK() and isRepeatPasswordOK()) {
val intent = Intent(this.requireContext(), MainActivity::class.java)
startActivity(intent)
}
}
return bind.root
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a function:

fun isValid() = isEmailOK() and isPasswordOK() and isRepeatPasswordOK()


private fun isEmailOK(): Boolean {
val editText = requireView().findViewById<EditText>(R.id.loginEditText)
if (!isEmailValid(editText.text.toString())) {
editText.error = "This is not an e-mail address"
return false
} else {
return true
}
}

private fun isEmailValid(email: String): Boolean {
return Pattern.compile(
"[a-zA-Z0-9+._%-]{1,256}" +
"@" +
"[a-zA-Z0-9][a-zA-Z0-9-]{0,64}" +
"(" +
"\\." +
"[a-zA-Z0-9][a-zA-Z0-9-]{0,25}" +
")+"
).matcher(email).matches()
}

private fun isPasswordOK(): Boolean {
val editText = requireView().findViewById<EditText>(R.id.passwordEditText)
if (editText.text.length < 5) {
editText.error = "Password must be at least 5 characters long"
return false
} else {
return true
}
}

private fun isRepeatPasswordOK(): Boolean {
val password = requireView().findViewById<EditText>(R.id.passwordEditText)
val repeatPassword = requireView().findViewById<EditText>(R.id.repeatPassword)
if (password.text.toString() != repeatPassword.text.toString()) {
repeatPassword.error = "Passwords do not match"
return false
} else {
return true
}
}
}