kaveer
9/18/2016 - 5:07 PM

Validation

Validation

EditText email;
EditText password;

email = (EditText)findViewById(R.id.TextboxEmailLogin);
password = (EditText)findViewById(R.id.TextboxPasswordLogin);

 public boolean ValidateEditText(){
        boolean result = true;

        if(email.getText().toString().trim().length() == 0){
            email.setError("Enter Email");
            return result = false;
        }

        if (!email.getText().toString().trim().matches("[a-zA-Z0-9._-]+@[a-z]+\\.+[a-z]+")){
            email.setError("Invalid Email Format");
            return result = false;
        }

        if(password.getText().toString().trim().length() <= 6){
            password.setError( "must be greater that 6 characters");
            return result = false;
        }
        return  result;
    }
 EditText email = (EditText)findViewById(R.id.TextboxEmail);
            String emailVariable = email.getText().toString();
            EditText password = (EditText)findViewById(R.id.TextboxPassword);
            String passwordVariable = password.getText().toString();
            EditText confirmPassword = (EditText)findViewById(R.id.TextboxConfirmPassword);
            String confirmPasswordVariable = confirmPassword.getText().toString();
            EditText firstname = (EditText)findViewById(R.id.TextboxFirstName);
            String firstnameVariable = firstname.getText().toString();
            EditText lastname = (EditText)findViewById(R.id.TextboxLastName);
            String lastnameVariable = lastname.getText().toString();
            EditText address = (EditText)findViewById(R.id.TextboxAddress);
            String addressVariable = address.getText().toString();
            EditText contact = (EditText)findViewById(R.id.TextboxContact);
            String contactVariable = contact.getText().toString();


           if(emailVariable.isEmpty() == true){
               email.setError("Enter Email");
               return;
           }

           if(passwordVariable.isEmpty() == true){
                password.setError("Enter Password");
           }

           if(passwordVariable.length() <= 6){
                password.setError( "must be greater that 6 characters");
                return;
           }


           if(ValidatePassword(passwordVariable , confirmPasswordVariable)== false){
                confirmPassword.setError("Password don't match");
                return;
           }

           if (firstnameVariable.isEmpty() == true){
                firstname.setError("Enter Firstname");
                return;
           }

           if(lastnameVariable.isEmpty() == true){
               lastname.setError("Enter Lastname");
               return;
           }
EditText password = (EditText)findViewById(R.id.TextboxPassword);//get valus from textbox
String passwordVariable = password.getText().toString();

EditText confirmPassword = (EditText)findViewById(R.id.TextboxConfirmPassword);//get valus from textbox
String confirmPasswordVariable = confirmPassword.getText().toString();

 if(ValidatePassword(passwordVariable , confirmPasswordVariable)== true){
                Intent i = new Intent(SignUp.this, VMS.class);
                startActivity(i);
            }
            

  public boolean ValidatePassword(String password , String confirmPassword)
    {

        if (!password.equals(confirmPassword)) {

            Toast msgbox = Toast.makeText(SignUp.this , "Password don't match" , Toast.LENGTH_SHORT);
            msgbox.show();

            return false;
        }
        return true;
    }
 RadioGroup vehicleRadioGroup;
    EditText taxPaymentDate;
    EditText taxCost;
    EditText taxExpiryDate;


vehicleRadioGroup =(RadioGroup)view.findViewById(R.id.TaxVehicleRadioButton);
        taxPaymentDate = (EditText)view.findViewById(R.id.TaxPayDate);
        taxCost = (EditText)view.findViewById(R.id.TaxCost);
        taxExpiryDate = (EditText)view.findViewById(R.id.TaxExpiryDate);

private boolean IsValid() {
        boolean result = true;

        if(vehicleRadioGroup.getCheckedRadioButtonId() == -1){
            Toast messageBox = Toast.makeText(getActivity() , "Select a vehicle to update" , Toast.LENGTH_SHORT);
            messageBox.show();
            return false;
        }

        if(taxPaymentDate.getText().toString().trim().length() == 0){
            taxPaymentDate.setError("Enter Payment date");
            return false;
        }

        if(!taxPaymentDate.getText().toString().trim().matches("(((19|20)([2468][048]|[13579][26]|0[48])|2000)[/-]02[/-]29|((19|20)[0-9]{2}[/-](0[4678]|1[02])[/-](0[1-9]|[12][0-9]|30)|(19|20)[0-9]{2}[/-](0[1359]|11)[/-](0[1-9]|[12][0-9]|3[01])|(19|20)[0-9]{2}[/-]02[/-](0[1-9]|1[0-9]|2[0-8])))")){
            taxPaymentDate.setError("Invalid date(YYYY-MM-DD)");
            return false;
        }

        if(taxCost.getText().toString().trim().length() == 0){
            taxCost.setError("Enter cost");
            return false;
        }

        if(taxExpiryDate.getText().toString().trim().length() == 0){
            taxExpiryDate.setError("Enter expiry date");
            return false;
        }

        if(!taxExpiryDate.getText().toString().trim().matches("(((19|20)([2468][048]|[13579][26]|0[48])|2000)[/-]02[/-]29|((19|20)[0-9]{2}[/-](0[4678]|1[02])[/-](0[1-9]|[12][0-9]|30)|(19|20)[0-9]{2}[/-](0[1359]|11)[/-](0[1-9]|[12][0-9]|3[01])|(19|20)[0-9]{2}[/-]02[/-](0[1-9]|1[0-9]|2[0-8])))")){
            taxExpiryDate.setError("Invalid date(YYYY-MM-DD)");
            return false;
        }

        return  result;
    }