欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java过滤特殊符号

程序员文章站 2022-05-26 17:55:33
...
public class Tool {
	
	private static String[] noChar={"'","%","^","&","?","(",")","<",">","[","]","{","}","/","\\",";",":","--","\""," "};  //检查是否包含特殊字符

	public static boolean YanZheng(String zifu)
	{
		for(int i=0;i<noChar.length;i++)
		{
			if(zifu.contains(noChar[i]))
			{				
				return false;
			}
		}
		return true;
	}
	
	public static boolean YanZheng(String zifu,String zifu2)
	{
		for(int i=0;i<noChar.length;i++)
		{
			if(zifu.contains(noChar[i]) || zifu2.contains(noChar[i]))
			{
				return false;
			}
		}
		return true;
	}

}
 
相关标签: Java