How to add custom Patterns

I have a referral system in my Android app with codes that look like this : ####-####-####

I know how to do for the Patterns of the email address I code you below

private boolean checkEmail() {
        String email = email_tv.getText().toString();
        if (!email.isEmpty() && Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
            checkPassword(email);
            return true;
        } else {
            Toast.makeText(Register.this, "Vérifiez votre email", Toast.LENGTH_SHORT).show();
            return false;
        }
    }

This Patterns.EMAIL_ADDRESS checks if the Text corresponds to a type of email address

I would like my Pattern to look like this ####-####-####, know how to do it? If you have another method I want it!

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

Use this pattern : \w\w\w\w-\w\w\w\w-\w\w\w\w and this good web page : https://regex101.com/

How to add custom Patterns

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply