2008-05-12
java 正则表达式
/**
*版权只属于未来客
*/
import java.util.regex.Pattern;
/**
* @since 2008-05-10
* @author 未来客
* @version 1.0
*/
public class StrTest {
public StrTest(){
}
/**
* @desc 判断是否全是字母
* @param str
* @return
*/
public boolean letterMatch(String str){
if(Pattern.matches("[a-zA-Z]*",str)){
return true;
}
else{
return false;
}
}
/**
* @desc 判断是否全是数字
* @param str
* @return
*/
public boolean numberMatch(String str){
if(Pattern.matches("[0-9]*",str)){
return true;
}
else{
return false;
}
}
/**
* @desc 判断不包含某些字符
* @param str
* @return
*/
public boolean containLetterMatch(String str){
if(Pattern.matches("[a-zA-Z0-9&&[^bc]]*",str)){
return true;
}
else{
return false;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
StrTest test=new StrTest();
System.out.println(test.letterMatch("adfdsafjksdafljsadklf"));
System.out.println(test.numberMatch("3255325235235252353252"));
System.out.println(test.containLetterMatch("sddsfgdfsZZFS5465464654FDS"));
}
}
*版权只属于未来客
*/
import java.util.regex.Pattern;
/**
* @since 2008-05-10
* @author 未来客
* @version 1.0
*/
public class StrTest {
public StrTest(){
}
/**
* @desc 判断是否全是字母
* @param str
* @return
*/
public boolean letterMatch(String str){
if(Pattern.matches("[a-zA-Z]*",str)){
return true;
}
else{
return false;
}
}
/**
* @desc 判断是否全是数字
* @param str
* @return
*/
public boolean numberMatch(String str){
if(Pattern.matches("[0-9]*",str)){
return true;
}
else{
return false;
}
}
/**
* @desc 判断不包含某些字符
* @param str
* @return
*/
public boolean containLetterMatch(String str){
if(Pattern.matches("[a-zA-Z0-9&&[^bc]]*",str)){
return true;
}
else{
return false;
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
StrTest test=new StrTest();
System.out.println(test.letterMatch("adfdsafjksdafljsadklf"));
System.out.println(test.numberMatch("3255325235235252353252"));
System.out.println(test.containLetterMatch("sddsfgdfsZZFS5465464654FDS"));
}
}
发表评论
最近加入圈子
最新评论
-
java 正则表达式
if(Pattern.matches("[a-zA-Z]*",str)){ r ...
-- by cris_jxg -
STRUTS2.0 常用标签 strut ...
哈哈 怎么就写了一篇文章啊
-- by rujingzhang







评论排行榜