Click here to Skip to main content
15,936,119 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can i validate when a user want to register in my app,i have tried different ways but still registration is done even if no details are given.I want to set errors on click before details are inserted into database

What I have tried:

public class Register extends AppCompatActivity {

    EditText name1, etpolicyNumber, etPassword;
    Button bRegister;
    private AwesomeValidation awesomeValidation;

    protected void onCreate(Bundle savedInstanceState) {

        awesomeValidation = new AwesomeValidation(ValidationStyle.BASIC);

        name1 = (EditText) findViewById(;
        etpolicyNumber = (EditText) findViewById(;
        etPassword = (EditText) findViewById(;
        bRegister = (Button) findViewById(;

        awesomeValidation.addValidation(this,, "^[A-Za-z\\s]{1,}[\\.]{0,1}[A-Za-z\\s]{0,}$", R.string.nameerror);
        awesomeValidation.addValidation(this,, "^[A-Za-z\\s]{1,}[\\.]{0,1}[A-Za-z\\s]{0,}$",R.string.policynumbererror);
        awesomeValidation.addValidation(this,, "^[A-Za-z\\s]{1,}[\\.]{0,1}[A-Za-z\\s]{0,}$", R.string.passworderror);

        bRegister.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                String name = name1.getText().toString();
                String policyNumber = etpolicyNumber.getText().toString();
                String password = etPassword.getText().toString();
Response.Listener<String> responseListener = new Response.Listener<String>() {
                    public void onResponse(String response) {
                        try {
                            JSONObject jsonResponse = new JSONObject(response);
                            boolean success = jsonResponse.getBoolean("success");
                            if (success) {

                                Intent intent = new Intent(Register.this, MainActivity.class);
                                Toast.makeText(Register.this, "Registration Successful", Toast.LENGTH_SHORT).show();
                            } else {
                                AlertDialog.Builder builder = new AlertDialog.Builder(Register.this);
                                builder.setMessage("Register Failed")
                                        .setNegativeButton("Retry", null)

                        } catch (JSONException e) {

                RegisterRequest registerRequest = new RegisterRequest(name, policyNumber, password, responseListener);
                RequestQueue queue = Volley.newRequestQueue(Register.this);


Updated 20-Jun-17 2:58am
ZurdoDev 19-Jun-17 8:38am    
Debug your code.

Initially disable the Register button.  Only enable it after the Name, Policy Number, and Password fields are filled in (and validated).
Share this answer
Member 13053943 19-Jun-17 15:08pm    
how will i disable it,can use the code i sent and and change it for me?
David Crow 19-Jun-17 15:47pm    
You can do it in code, but I would initially disable it in the layout's XML file.
If I have understood your question correctly
I would personally do this,

Fist of all I will get the user input into a String

String example = editText.getText().toString().trim()
// and validate it
if(example.equals("") // If the input is nothing
   editText.setError("Your error message"); // or editText.setError(getString(R.string.errorMessage));

// Proceed registration

Add this on your OnClickListener()for the button
Share this answer
David Crow 20-Jun-17 22:09pm    
I personally find it particularly annoying when I am allowed to click a (OK) button when there is an error; this violates the basic principles of good GUI design. In other words, don't let the user have access to something, and then complain when they misuse it.
[no name] 21-Jun-17 12:51pm    
Sir,I have a doubt sir - If we have a long form and disabled the "OK\SUBMIT" button and allowed only when the full form is filled correctly, if the user accidentally misses something he needs to review the whole form since the OK button is not enabled this is more annoying since the user may not find the error forever and will never uses the application. I have used various apps and none of them have disabled the button like login, submit etc., all are error showing mechanisms.

What needs to be done in this case?

Thank you for your time sir
David Crow 21-Jun-17 15:33pm    
If you have a "long form" and "the user may not find the error forever" I would say that is a design issue. You shouldn't try to fit an entire job or loan application on one form, for example. Break it up into smaller, more manageable pieces that CAN be controlled.

Having dealt with Microsoft products for the past three decades has caused me to develop somewhat of a jaded view toward messages: 1) they shouldn't cause more confusion than the issue that actually raised them, and 2) they should either be the solution or point me in the direction of the solution. I feel that having a whole plethora of "You did not enter xyz" messages is confusing, annoying, and unnecessary.
I disable the login and registration button unless values are set into the fields before you can submit...i used a text watcher so i think so far its been good.if you are a user and you submit wrong info,that will be your problem because,the system is gabage in gabage out..if you type John as Jonh,it will be accepted by the system...the system know which name is wrong..thanks for your support...error validation has been set in php and android
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900