📄 jmchecktype.java
字号:
*/
public static boolean isString2byte(String strInput) {
if (strInput == null || strInput.length() == 0) {
return true;
}
// 慡妏偺応崌偺懳張傕峫椂偟偰丄壗僶僀僩暘偺挿偝偱偁傞偐傪庢摼
int blength = 0;
int length = 0;
try {
blength = strInput.getBytes(ENCODING).length;
length = strInput.length();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
if (blength / 2 != length) { // 僶僀僩悢/2偑暥帤悢偲摍偟偔側偄応崌
return false;
}
return true;
}
/**
* YYYY/MM/DD偱庴偗偲偭偨擔晅偑惓偟偄偐偳偆偐僠僃僢僋偡傞 <BR>
* 椺奜偲偟偰丄9999/99/99偼true傪曉偡丅
*
* <PRE>
* null傕偟偔偼嬻暥帤偺応崌偼丄true傪曉偟傑偡丅
* </PRE>
*
* @param strInput
* 僠僃僢僋懳徾偺暥帤楍
* @return boolean 惓偟偗傟偽 true 偦偆偱側偗傟偽 false
*/
public static boolean isDateConsistency(String strInput) {
boolean blnFlag = false;
int intYear = 999;
int intMonth = 999;
int intDay = 999;
if (strInput == null || strInput.length() == 0) {
return true;
}
if (strInput.equals("9999/99/99")) {
return true;
}
if (strInput.length() == 10) {
if (strInput.substring(4, 5).equals("/") && strInput.substring(7, 8).equals("/")) {
try {
intYear = Integer.parseInt(strInput.substring(0, 4));
intMonth = Integer.parseInt(strInput.substring(5, 7));
intDay = Integer.parseInt(strInput.substring(8, 10));
} catch (NumberFormatException e) {
return false;
}
Calendar cal = GregorianCalendar.getInstance();
cal.set(intYear, (intMonth - 1), intDay);
if (intYear == cal.get(Calendar.YEAR) && (intMonth - 1) == cal.get(Calendar.MONTH)
&& intDay == cal.get(Calendar.DATE)) {
blnFlag = true;
}
}
}
return blnFlag;
}
/**
* 彫悢偺惍悢晹暘寘悢偲彫悢晹暘寘悢偺僠僃僢僋 <BR>
*
* <PRE>
* null傕偟偔偼嬻暥帤偺応崌偼丄true傪曉偟傑偡丅
* </PRE>
*
* @param str
* 僠僃僢僋懳徾偺暥帤楍
* @param num1
* 惍悢晹寘悢
*
* @param num2
* 彫悢晹寘悢
*
* @return 僠僃僢僋寢壥丅True側傜Null傑偨偼僽儔儞僋偱側偄 False側傜Null傑偨偼僽儔儞僋
*/
public static boolean isDecimal(String str, int num1, int num2) {
if (str == null || str.length() == 0) {
return true;
}
int idx = 0;
String strNum = "";
String strDec = "";
idx = str.indexOf(".", 0);
if (idx <= 0) {
//悢抣僠僃僢僋
if(!isNumber(str)){
return false;
}
if (str.length() > num1) {
return false;
} else {
return true;
}
} else {
strNum = str.substring(0, idx);
strDec = str.substring(idx + 1);
//悢抣僠僃僢僋
if((isNumber(strNum) && isHalfNumber(strDec))==false){
return false;
}
//Add End 2005/09/07 栘壓柅婯(JBCC)
if (strNum.length() > num1 || strDec.length() > num2) {
return false;
} else {
return true;
}
}
}
/**
* YYYYMMDD偱庴偗偲偭偨擔晅偑惓偟偄偐偳偆偐僠僃僢僋偡傞 <BR>
* 椺奜偲偟偰丄99999999偼true傪曉偡丅
*
* @param strInput
* 僠僃僢僋懳徾偺暥帤楍
* @return boolean 惓偟偗傟偽 true 偦偆偱側偗傟偽 false
*/
public static boolean isNumDateConsistency(String strInput){
boolean blnFlag = false;
int intYear = 999;
int intMonth = 999;
int intDay = 999;
if (strInput == null || strInput.equals("")) {
return true;
}else{
strInput=JMENDateUtil.setDateString(strInput);
}
if (strInput.length() == 8) {
try {
intYear = Integer.parseInt(strInput.substring(0, 4));
intMonth = Integer.parseInt(strInput.substring(4, 6));
intDay = Integer.parseInt(strInput.substring(6, 8));
} catch (NumberFormatException e) {
return false;
}
Calendar cal = GregorianCalendar.getInstance();
cal.set(intYear, (intMonth - 1), intDay);
if (intYear == cal.get(Calendar.YEAR)
&& (intMonth - 1) == cal.get(Calendar.MONTH)
&& intDay == cal.get(Calendar.DATE)) {
blnFlag = true;
}
}
return blnFlag;
}
/**
* <H3>嬥妟僠僃僢僋.</H3>
*
* <PRE>
*
* 埲壓偺忦審偵崌偆応崌丄true傪曉偟傑偡丅 <br>
* 9999 +9999 -9999 +9,999 -9,999 9,999 99,999,999<br>
*
* </PRE>
*
* @return 懳徾暥帤偱偁傟偽 true丄偦傟埲奜偼 false
* @param strMoney
* 僠僃僢僋懳徾暥帤楍
*/
public static boolean isMoney(String strMoney) {
if (strMoney == null || strMoney.length() == 0) {
return true;
}
if(strMoney.startsWith("0") && strMoney.length() > 1){
return false;
}
if(strMoney.startsWith("+") && strMoney.indexOf("0") == 1){
return false;
}
if(strMoney.startsWith("-") && strMoney.indexOf("0") == 1){
return false;
}
if(strMoney.indexOf("+") > 0 && !(strMoney.startsWith("-"))){
return false;
}
if(strMoney.indexOf("-") > 0 && !(strMoney.startsWith("+"))){
return false;
}
if(strMoney.startsWith(",")){
return false;
}
StringCharacterIterator sci = new StringCharacterIterator(strMoney);
int flag = 0;
for (char c = sci.first(); c < CharacterIterator.DONE; c = sci.next()) {
if ((c >= '0' && c <= '9') || c == ',' || c == '+' || c == '-') { //敿妏悢帤
if(c == '+' || c == '-'){
flag ++ ;
}
if(flag > 1){
return false;
}
} else {
return false;
}
}
if(strMoney.lastIndexOf(",") < 0 ){
return true;
}
char [] strChar = strMoney.toCharArray();
char [] tempChar = new char[strChar.length];
int j=0;
for(int i=strChar.length-1; i >= 0;i--){
tempChar[j] = strChar[i];
j++;
}
for(int i =0; i<tempChar.length; i++){
int n = i+1;
if(tempChar[i] == ',' && ! (n%4 == 0)){
return false;
}
}
return true;
}
/**
* <H3>敿妏塸帤僠僃僢僋.</H3>
*
* <PRE>
*
* 敿妏塸帤偺僠僃僢僋傪偟傑偡丅 <br>
* 懳徾暥帤 丗塸戝暥帤丄塸彫暥帤乮慡偰敿妏乯 <br>
* 埲壓偺忦審偵崌偆応崌丄true傪曉偟傑偡丅 <br>
* <ul>
* <li>prmStr偑null丄傕偟偔偼挿偝偑0丅
* <li>prmStr偺奺暥帤偑丄'A' 乣 'Z'丄'a' 乣 'z'偺応崌丅
* </ul>
*
* 埲壓偺忦審偵崌偆応崌丄false傪曉偟傑偡丅 <BR>
* <ul>
* <li>prmStr偺奺暥帤偑丄'A' 乣 'Z'丄'a' 乣 'z'偺偄偢傟偱傕側偄応崌丅
* </ul>
*
* </PRE>
*
* @return 懳徾暥帤偱偁傟偽 true丄偦傟埲奜偼 false
* @param prmStr
* 僠僃僢僋懳徾暥帤楍
*/
public static boolean isHalfEnglish(String prmStr) {
if (prmStr == null || prmStr.length() == 0) {
return true;
}
StringCharacterIterator sci = new StringCharacterIterator(prmStr);
for (char c = sci.first(); c < CharacterIterator.DONE; c = sci.next()) {
if ((c >= 'A' && c <= 'Z') || //敿妏塸戝暥帤
(c >= 'a' && c <= 'z')) { //敿妏塸彫暥帤
} else {
return false;
}
}
return true;
}
/**
* 暥帤楍偑揹榖斣崋偱峔惉偝傟偰偄傞偐傪僠僃僢僋偡傞
*
* <PRE>
* null傕偟偔偼嬻暥帤偺応崌偼丄true傪曉偟傑偡丅
* </PRE>
*
* @param strInput
* 僠僃僢僋懳徾偺暥帤楍
* @return boolean 揹榖斣崋側傜 true 偦偆偱側偗傟偽 false
*/
public static boolean isTel(String strInput) {
if (strInput == null || strInput.length() == 0) {
return true;
}
for (int i = 0; i < strInput.length(); i++) {
char c = strInput.charAt(i);
if ((c < '0' || c > '9') && // 悢帤偱側偄
(c != '-') //'-'偱側偄
) {
return false;
}
}
return true;
}
/**
* 帪娫僠僃僢僋丂HHMMSS丂OR丂HHMM
* @param strInput 僠僃僢僋懳徾偺暥帤楍
* @return boolean 帪娫彂幃偲娫堘偄帪 false
*/
public static boolean isTime(String strInput) {
int h = 0;
int m = 0;
int s = 0;
//僽儔儞僋帪丄True傪栠傞
if(strInput == null || strInput == ""){
return true;
}
//4寘偲6寘埲奜丄Flase傪栠傞
if (strInput.length() != 4 && strInput.length() != 6){
return false;
}
//敿妏悢帤埲奜丄False傪栠傞
if (!isHalfNumber(strInput)){
return false;
}
//帪丄暘丄昩傪暘妱
h = Integer.parseInt(strInput.substring(0,2));
m = Integer.parseInt(strInput.substring(2,4));
if (strInput.length() == 6){
s = Integer.parseInt(strInput.substring(4,6));
}
//帪丄暘丄昩偺僠僃僢僋
if ( 0 > h || h > 24) return false;
if ( 0 > m || m > 60) return false;
if ( 0 > s || s > 60) return false;
return true;
}
/**
* 僷儔儊乕僞偑敿妏僇僫偩偗偐偳偆偐傪敾掕偡傞
*
* @param text丗僠僃僢僋偡傞暥帤楍
* @return 栠傝抣丗敾掕寢壥乮true丗慡偰敿妏僇僫暥帤丆false丗敿妏僇僫埲奜偺暥帤傪娷傫偱偄傞乯
*/
public static boolean isKana(String text) {
char startChar = '?';
char endChar = '?';
if (text==null || text.trim().length()==0) return true;
for (int i = 0; i < text.length(); i++) {
char temp = text.charAt(i);
if (!(startChar <= temp && temp <= endChar)) {
return false;
}
}
return true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -