⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accountutil.java

📁 一个Java写的音乐网站应用小程序
💻 JAVA
字号:
package music.ejb.db;

import music.shared.*;

/**
 * 工具类,检查Account字段的格式
 */
public class AccountUtil {

    private static final String USERNAME = "[a-zA-Z][a-zA-Z0-9]+";
    private static final String PASSWORD = "[a-zA-Z0-9]+";

    public static void checkAccountFormat(AccountVO account) throws FormatException {
        checkUsernameFormat(account.getUsername());
        checkPasswordFormat(account.getPassword());

        // make the username lower case:
        account.setUsername(account.getUsername().toLowerCase());
    }

    public static void checkPasswordFormat(String password) throws FormatException {
        if(password==null)
            throw new FormatException("Password mustn't be empty.");
        int length = password.length();
        if(length<6 || length>20)
            throw new FormatException("Password must be 6 to 20 characters.");
        if(!password.matches("[a-zA-Z0-9]+"))
            throw new FormatException("Password must be alphabet or decimal or mixed.");
    }

    public static void checkUsernameFormat(String username) throws FormatException {
        // check username:
        if(username==null)
            throw new FormatException("Username mustn't be empty.");
        int length = username.length();
        if(length<3 || length>20)
            throw new FormatException("Username must be 3 to 20 characters.");
        if(!username.matches(USERNAME))
            throw new FormatException("Username must be alphabet or decimals, and begin with an alphabet.");
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -