昵称只能输入中文英文数字

很简单,不多说,直接上代码

	public static Boolean nicknameDetermine(String nickname) {
		Boolean flag = true;
		String reg1 = "[\\u4e00-\\u9fa5]";
		String reg2 = "[a-zA-Z]";
		String reg3 = "[0-9]";
		
		char[] charArray = nickname.toCharArray();
		for (char c : charArray) {
			String str = String.valueOf(c);
			if(!str.matches(reg1) && !str.matches(reg2) && !str.matches(reg3)) {
				flag = false;
				break;
			}
		}
		
		
		return flag;
	}


你可能感兴趣的:(Java基础)