Tuesday 26 June 2018

Password Validation

package com.dhananjay.demoravicontact.allsetting.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.dhananjay.demoravicontact.R;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AllSettingActivity extends AppCompatActivity {
    protected static final String TAG = "AllSettingActivity";
    EditText password_edittext;
    Button send_button;

    @Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_all_setting);
        password_edittext=(EditText)findViewById(R.id.password_edittext);
        send_button=(Button) findViewById(R.id.send_button);

        send_button.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                if(password_edittext.getText().toString().length()<8
 &&!isValidPassword(password_edittext.getText().toString())){
                    System.out.println("Not Valid");
                    Toast.makeText(AllSettingActivity.this, "Not Valid", 
Toast.LENGTH_SHORT).show();
                }else{
                    Toast.makeText(AllSettingActivity.this, "Valid", 
Toast.LENGTH_SHORT).show();
                    System.out.println("Valid");
                }
            }
        });
    }

    @Override    protected void onResume() {
        super.onResume();

    }
    public static boolean isValidPassword(final String password) {

        Pattern pattern;
        Matcher matcher;
        final String PASSWORD_PATTERN =
 "^(?=.*[0-9])(?=.*[A-Z])(?=.*[@#$%^&+=!])(?=\\S+$).{4,}$";
        pattern = Pattern.compile(PASSWORD_PATTERN);
        matcher = pattern.matcher(password);

        return matcher.matches();

    }

}

No comments:

Post a Comment

AutoComplete Address (Updated)

-------------------------------------Activity---------------------------------- package placeautocomplete.iteritory.com; import androi...