Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.support.annotation.NonNull;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main {
    public static final int VERIFY_SUCCESS = 0;
    private static final int VERIFY_LENGTH_ERROR = 1;
    private static final int VERIFY_TYPE_ERROR = 2;

    public static int verifyPassword(@NonNull String password) {

        int length = password.length();
        if (length < 6 || length > 18) {
            return VERIFY_LENGTH_ERROR;
        }

        String regex = "^\\w+$";
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(password);

        if (!matcher.matches())
            return VERIFY_TYPE_ERROR;
        return VERIFY_SUCCESS;
    }
}