public class JudgeChar
{
String str = "86ggfd475";
private void judgement()
{
for(int i=0;i<str.length();i++)
{
switch(str.charAt(i))
{
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
continue;
public class Test{
public final static String REG_DIGIT="[0-9]*";
public final static String REG_CHAR="[a-zA-Z]*";
public Test(){}
public boolean isDigit(String str){
return str.matches(REG_DIGIT);
}
public boolean isChar(String str){
return str.matches(REG_CHAR);
}
public static void main(String args[]){
Test t=new Test();
String s1="dsssdcd";
String s2="4014810";
String s3="jflj998";
System.out.println("s1 is a non-digit string:"+t.isChar(s1));
System.out.println("s1 is a digit string:"+t.isDigit(s1));
System.out.println("s2 is a non-digit string:"+t.isChar(s2));
System.out.println("s2 is a digit string:"+t.isDigit(s2));
System.out.println("s3 is a non-digit string:"+t.isChar(s3));
System.out.println("s3 is a digit string:"+t.isDigit(s3));
}
[/PHP]
输出结果
[PHP]
s1 is a non-digit string:true
s1 is a digit string:false
s2 is a non-digit string:false
s2 is a digit string:true
s3 is a non-digit string:false
s3 is a digit string:false