Java tutorial
//package com.java2s; public class Main { public static boolean isMucNickNameLegal(String nickName) { nickName = nickName.trim(); String name = nickName.replaceAll("[^a-zA-Z0-9_@~!,\\[\\]\\-=+#\'\";?()!*\\s]", "**"); int len = name.length(); if (len == 0 || (len >= 2 && len <= 20)) { return true; } return false; } }