I would recommend validation upon input processing in an android application, generally in the form button's onClick function.
emailEditText = (EditText) findViewById(R.id.editText_email);
passEditText = (EditText) findViewById(R.id.editText_password);
findViewById(R.id.btn_signup).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
final String email = emailEditText.getText().toString();
if (!isValidEmail(email)) {
emailEditText.setError("Invalid Email");
}
final String pass = passEditText.getText().toString();
if (!isValidPassword(pass)) {
passEditText.setError("Invalid Password");
}
}
});
}
// validating email id
private boolean isValidEmail(String email) {
String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
Pattern pattern = Pattern.compile(EMAIL_PATTERN);
Matcher matcher = pattern.matcher(email);
return matcher.matches();
}
// validating password with retype password
private boolean isValidPassword(String pass) {
if (pass != null && pass.length() > 6) {
return true;
}
return false;
}
I have found regular expressions to be the best way to do this.
Front end code cannot be manipulated in android, as each application is compiled into an apk (off the device) then installed on the device and run. It may however be possible to modify web traffic going in and out the device, but that requires a rooted device, but simple security strategies like using https: and well made json is a way to help prevent this.