Android 姓名的校驗

/**
 * 驗證輸入的名字是否爲中文或者是否包含“·”
 * @param str w爲用戶輸入的姓名
 * @return
 */
public static boolean verifyName(String str) {
    if (str.contains("·") || str.contains("•")) {
        if (str.matches("^[\\u4e00-\\u9fa5]+[·•][\\u4e00-\\u9fa5]+$")) {
            return true;
        } else {
            return false;
        }
    } else {
        if (str.matches("^[\\u4e00-\\u9fa5]+$")) {
            return true;
        } else {
            return false;
        }
    }
}
發佈了74 篇原創文章 · 獲贊 45 · 訪問量 16萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章