Example usage for android.util Patterns EMAIL_ADDRESS

List of usage examples for android.util Patterns EMAIL_ADDRESS

Introduction

In this page you can find the example usage for android.util Patterns EMAIL_ADDRESS.

Prototype

Pattern EMAIL_ADDRESS

To view the source code for android.util Patterns EMAIL_ADDRESS.

Click Source Link

Usage

From source file:Main.java

public static boolean isTextEmailAddress(final @NonNull CharSequence text) {
    return Patterns.EMAIL_ADDRESS.matcher(text).matches();
}

From source file:Main.java

/**
 * Returns true if the given string is an email.
 *//*from w  w  w .j av  a 2 s.  c  o  m*/
private static boolean isEmail(String account) {

    if (TextUtils.isEmpty(account)) {
        return false;
    }

    final Pattern emailPattern = Patterns.EMAIL_ADDRESS;
    final Matcher matcher = emailPattern.matcher(account);
    return matcher.matches();
}

From source file:co.edu.uniajc.vtf.security.controller.ForgotPasswordController.java

private boolean validate() {
    String lsMessage = "";
    boolean lboResult = true;
    ResourcesManager loResource = new ResourcesManager((Activity) this.coView);

    if (this.coView.getEmail().equals("")) {
        lsMessage = loResource.getStringResource(R.string.general_email_invalid_message);
        lboResult = false;/*w ww  .  ja  v a2s. c o m*/
    } else if (!Patterns.EMAIL_ADDRESS.matcher(this.coView.getEmail()).matches()) {
        lsMessage = loResource.getStringResource(R.string.general_email_invalid_message2);
        lboResult = false;
    }
    if (!lboResult)
        AlertDialogManager.showAlertDialog((Activity) coView,
                loResource.getStringResource(R.string.general_message_error), lsMessage,
                AlertDialogManager.ERROR);

    return lboResult;
}

From source file:com.victorkifer.AndroidTemplates.fragments.SignInFragment.java

private int checkInput() {
    int result = Activity.RESULT_OK;
    if (etEmail.getText() == null || etEmail.getText().length() == 0) {
        etEmail.setError(getString(R.string.err_email_empty));
        result = Activity.RESULT_CANCELED;
    } else {/*from   w w  w.j  a  va2s .  co  m*/
        Pattern emailPattern = Patterns.EMAIL_ADDRESS;
        if (!emailPattern.matcher(etEmail.getText()).matches()) {
            etEmail.setError(getString(R.string.err_not_an_email));
            result = Activity.RESULT_CANCELED;
        }
    }

    if (etPassword.getText() == null || etPassword.getText().length() == 0) {
        etPassword.setError(getString(R.string.err_password_empty));
        result = Activity.RESULT_CANCELED;
    } else if (etPassword.getText().length() < minPasswordLength) {
        etPassword.setError(getString(R.string.err_password_too_short));
        result = Activity.RESULT_CANCELED;
    }
    return result;
}

From source file:co.edu.uniajc.vtf.security.controller.CreateAccountController.java

private boolean validate() {
    String lsMessage = "";
    boolean lboResult = true;
    ResourcesManager loResource = new ResourcesManager((Activity) this.coView);

    if (this.coView.getEmail().equals("")) {
        lsMessage = loResource.getStringResource(R.string.general_email_invalid_message);
        lboResult = false;//w  ww  .  ja  v  a2s  . c  o m
    } else if (!Patterns.EMAIL_ADDRESS.matcher(this.coView.getEmail()).matches()) {
        lsMessage = loResource.getStringResource(R.string.general_email_invalid_message2);
        lboResult = false;
    } else if (this.coView.getPassword().equals("")) {
        lsMessage = loResource.getStringResource(R.string.general_password_invalid_message);
        lboResult = false;
    } else if (this.coView.getPassword().length() < 6) {
        lsMessage = loResource.getStringResource(R.string.general_password_invalid_message2);
        lboResult = false;
    } else if (!this.coView.getPassword().equals(this.coView.getRepeatPassword())) {
        lsMessage = loResource.getStringResource(R.string.general_password_invalid_message3);
        lboResult = false;
    } else if (this.coView.getNames().equals("")) {
        lsMessage = loResource.getStringResource(R.string.general_names_invalid_message);
        lboResult = false;
    }

    if (!lboResult)
        AlertDialogManager.showAlertDialog((Activity) coView,
                loResource.getStringResource(R.string.general_message_error), lsMessage,
                AlertDialogManager.ERROR);
    return lboResult;
}

From source file:id.satusatudua.sigap.ui.LoginActivity.java

@OnClick(R.id.login)
public void login() {
    String email = this.email.getText().toString();
    String password = this.password.getText().toString();

    if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
        this.email.setError("Mohon masukan alamat email yang valid!");
    } else if (password.length() <= 0) {
        this.password.setError("Mohon masukan password anda disini!");
    } else {/*w  w w .j a v  a2s . c o m*/
        loginPresenter.login(email, password);
    }
}

From source file:es.hol.ecotiffins.view.RegisterActivity.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btnNextToSecondScreen:
        //Validating user to fill the required field & email validations
        //If user satisfies the conditions, we will move to the next screen
        //Otherwise set error to TextInputLayout
        if (editName.getText().toString().trim().length() > 0) {
            clearValidationError(findViewById(R.id.txtInputLayoutName));
            if (Patterns.EMAIL_ADDRESS.matcher(editEmail.getText().toString().trim()).matches()) {
                clearValidationError(findViewById(R.id.txtInputLayoutEmail));
                //Setting up animation to view flipper and moving to the next state
                viewFlipper.setInAnimation(this, R.anim.slide_in_from_right);
                viewFlipper.setOutAnimation(this, R.anim.slide_out_to_left);
                viewFlipper.showNext();//from  w  ww  .j a v a  2s  . co  m
            } else {
                setValidationError(findViewById(R.id.txtInputLayoutEmail),
                        getResources().getString(R.string.error_email));
            }
        } else {
            setValidationError(findViewById(R.id.txtInputLayoutName),
                    getResources().getString(R.string.name_empty));
        }
        break;

    case R.id.btnNextToThirdScreen:
        //Validating user to fill the required field
        //If user satisfies the conditions, we will move to the next screen
        //Otherwise set error to TextInputLayout
        if (editPhone.getText().toString().trim().length() == 10) {
            if (!(String.valueOf(editPhone.getText().toString().charAt(0)).equals("7")
                    || String.valueOf(editPhone.getText().toString().charAt(0)).equals("8")
                    || String.valueOf(editPhone.getText().toString().charAt(0)).equals("9"))) {
                setValidationError(findViewById(R.id.txtInputLayoutPhone),
                        getResources().getString(R.string.contact_validate));
            } else {
                clearValidationError(findViewById(R.id.txtInputLayoutPhone));
                if (editAddress.getText().toString().trim().length() > 10) {
                    clearValidationError(findViewById(R.id.txtInputLayoutAddress));
                    //Setting up animation to view flipper and moving to the next state
                    viewFlipper.setInAnimation(this, R.anim.slide_in_from_right);
                    viewFlipper.setOutAnimation(this, R.anim.slide_out_to_left);
                    viewFlipper.showNext();
                } else {
                    setValidationError(findViewById(R.id.txtInputLayoutAddress),
                            getResources().getString(R.string.address_empty));
                }
            }
        } else {
            setValidationError(findViewById(R.id.txtInputLayoutPhone),
                    getResources().getString(R.string.contact_empty));
        }
        break;

    case R.id.btnRegister:
        if (editPassword.getText().toString().length() < 6) {
            setValidationError(findViewById(R.id.txtInputLayoutPassword),
                    getResources().getString(R.string.password_empty));
        } else if (!(editPassword.getText().toString().equals(editConfirm.getText().toString()))) {
            clearValidationError(findViewById(R.id.txtInputLayoutPassword));
            setValidationError(findViewById(R.id.txtInputLayoutConfirmPassword),
                    getResources().getString(R.string.password_not_confirm));
        } else {
            clearValidationError(findViewById(R.id.txtInputLayoutConfirmPassword));
            registerUser();
        }
        break;
    case R.id.imgBack:
        //Setting up animation to view flipper
        viewFlipper.setInAnimation(this, R.anim.slide_in_from_left);
        viewFlipper.setOutAnimation(this, R.anim.slide_out_to_right);
        viewFlipper.showPrevious();
        break;
    }
}

From source file:com.github.jobs.ui.dialog.SubscribeDialog.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btn_subscribe:
        String emailAddress = mEmail.getText().toString().trim();
        Matcher matcher = Patterns.EMAIL_ADDRESS.matcher(emailAddress);
        if (!matcher.find()) {
            mEmail.setError(getString(R.string.invalid_email_address));
            mEmail.requestFocus();/*from   w  w w  . j  a v a  2  s  . c o m*/
            return;
        }

        Bundle extras = new Bundle();
        if (getIntent().getExtras() != null) {
            extras.putAll(getIntent().getExtras());
        }
        extras.putString(EmailSubscriberResolver.EXTRA_EMAIL, emailAddress);
        Groundy.queue(this, EmailSubscriberResolver.class, mEmailSubscriberReceiver.getReceiver(), extras);
        break;
    }
}

From source file:id.satusatudua.sigap.ui.LoginActivity.java

@OnClick(R.id.forgot_password)
public void forgotPassword() {
    String email = this.email.getText().toString();

    if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
        this.email.setError("Mohon masukan alamat email yang valid terlebih dahulu!");
    } else {/*w w  w.ja va 2 s  . c om*/
        showLoading();
        FirebaseApi.pluck().getApi().resetPassword(email, new Firebase.ResultHandler() {
            @Override
            public void onSuccess() {
                dismissLoading();
                new AlertDialog.Builder(LoginActivity.this).setIcon(R.mipmap.ic_launcher)
                        .setTitle(R.string.app_name).setCancelable(false)
                        .setMessage(
                                "Kami telah mengirimkan sebuah kode ke email yang anda masukan tadi, masukan kode tersebut ke form selanjutnya untuk mengubah kata sandi anda.")
                        .setPositiveButton("OK", (dialog, which) -> {
                            StateManager.pluck().setState(StateManager.State.ENTER_CODE);
                            StateManager.pluck().setLastEmail(email);
                            Intent intent = new Intent(LoginActivity.this, EnterCodeActivity.class);
                            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            startActivity(intent);
                        }).show().getButton(DialogInterface.BUTTON_POSITIVE)
                        .setTextColor(ContextCompat.getColor(LoginActivity.this, R.color.colorPrimary));
            }

            @Override
            public void onError(FirebaseError firebaseError) {
                dismissLoading();
                Snackbar snackbar = Snackbar.make(password, firebaseError.getMessage(), Snackbar.LENGTH_LONG);
                snackbar.getView().setBackgroundResource(R.color.colorAccent);
                snackbar.show();
            }
        });
    }
}

From source file:id.satusatudua.sigap.ui.RegisterActivity.java

@OnClick(R.id.register)
public void register() {
    String nama = this.nama.getText().toString();
    String email = this.email.getText().toString();
    String phoneNumber = phone.getText().toString();

    if (nama.isEmpty()) {
        this.nama.setError("Mohon masukan nama anda!");
    } else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
        this.email.setError("Mohon masukan alamat email yang valid!");
    } else if (!Patterns.PHONE.matcher(phoneNumber).matches()) {
        this.phone.setError("Mohon masukan no ponsel yang valid!");
    } else {/*from   ww w.  j av a  2  s.com*/
        User user = new User();
        user.setName(nama);
        user.setEmail(email);
        user.setPhoneNumber(phoneNumber);
        user.setMale(laki.isChecked());
        user.setFromApps(true);
        user.setStatus(User.Status.SIAP);
        registerPresenter.register(user);
    }
}