java正则表达式判断_Java正则表达式判断
/* 判斷是否為數字 */ ??? public static boolean isNumeric(String str) ??? { ??? ?if(str == null || str.isEmpty()){ ??? ??return false; ??? ?} ??????? Pattern pattern = Pattern.compile("[0-9]*"); ??????? Matcher isNum = pattern.matcher(str); ??????? if (!isNum.matches()) ??????? { ??????????? return false; ??????? } ??????? return true; ??? } ??? /* 判斷是否為數字或字母 */ ??? public static boolean isNumOrLetter(String str) { ??? Pattern pattern = Pattern.compile("^[a-zA-Z0-9]+$"); ??? Matcher isRight = pattern.matcher(str); ??? if (!isRight.matches()) ??? { ??????? return false; ??? } ??? return true; } /* 判斷是否有字母 */ public static boolean isLetter(String str) { ??? Pattern pattern = Pattern.compile(".*[a-zA-Z]+.*"); ??? Matcher islett = pattern.matcher(str); ??? if (!islett.matches()) ??? { ??????? return false; ??? } ??? return true; ? } /* 判斷是否為+號數字或字母 */ ?public static boolean isPlusNumOrLetter(String str) { ?Pattern pattern = Pattern.compile("^\\+?[a-zA-Z0-9]+$"); ///^\+?[0-9a-zA-Z]+$/ ?Matcher isRight = pattern.matcher(str); ?if (!isRight.matches()) ?{ ???? return false; ?} ?return true; }
總結
以上是生活随笔為你收集整理的java正则表达式判断_Java正则表达式判断的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql密码高级_mysql高级操作
- 下一篇: java 监听 变量_[Java学习小记