📄 jmchecktype.java
字号:
package jm.util ;
import java.io.UnsupportedEncodingException;
import java.text.CharacterIterator;
import java.text.StringCharacterIterator;
import java.util.Calendar;
import java.util.GregorianCalendar;
/**
* <H3>儐乕僥傿儕僥傿僋儔僗</H3>
*
* <PRE>
*
* 僠僃僢僋偺儐乕僥傿儕僥傿丒僋儔僗偱偡丅
*
* </PRE>
*
* @author fu_changyong(1shome)
* @see jdk1.5.2
* @version 1.5.2.2
*/
public class JMCheckType {
public static final String ENCODING = "shift_jis";
/**
* <H3>暥帤楍斾妑僠僃僢僋.</H3>
*
* <PRE>
*
* 戞擇堷悢偺暥帤偑戞堦堷悢偺暥帤傛傝戝偒偄偐傪僠僃僢僋偟傑偡丅 <br>
* 戝暥帤彫暥帤偺嬫暿側偟偱丄2 偮偺暥帤楍傪帿彂幃偵斾妑偟傑偡丅 <br>
* 戞堦堷悢 < 戞擇堷悢 : true 戞堦堷悢 > 戞擇堷悢 : false
*
* </PRE>
*
* @param fromStr
* java.lang.String
* @param toStr
* java.lang.String
* @return boolean
*/
public static boolean isBig(String fromStr, String toStr) {
if (isEmpty(fromStr)) {
fromStr = "";
}
if (isEmpty(toStr)) {
return false;
}
if (toStr.compareToIgnoreCase(fromStr) < 0) {
return false;
}
return true;
}
/**
* <H3>null丒嬻暥帤僠僃僢僋.</H3>
*
* <PRE>
*
* 暥帤楍偑埲壓偺忦審偵崌偆応崌偼丄true傪曉偟傑偡丅 <br>
* <ul>
* <li>prmString偑null丅
* <li>prmString偺挿偝偑0丅
* </ul>
*
* </PRE>
*
* @param prmString
* 僠僃僢僋懳徾暥帤楍
* @return 暥帤楍偑 null 傕偟偔偼嬻偺応崌偼 true丄偦傟埲奜偼 false
*/
public static boolean isEmpty(String prmString) {
// 擖椡暥帤偺null僠僃僢僋
if (prmString == null) {
return true;
}
// 擖椡暥帤偺挿偝僠僃僢僋
if (prmString.length() == 0) {
return true;
}
return false;
}
/**
* <H3>敿妏悢帤僠僃僢僋.</H3>
*
* <PRE>
*
* 敿妏悢帤偺僠僃僢僋傪偟傑偡丅 <br>
* 懳徾暥帤 丗 悢帤丄塸戝暥帤丄塸彫暥帤乮慡偰敿妏乯 <br>
* 埲壓偺忦審偵崌偆応崌丄true傪曉偟傑偡丅 <br>
* <ul>
* <li>prmStr偑null丄傕偟偔偼挿偝偑0丅
* <li>prmStr偺奺暥帤偑丄'0' 乣 '9'偺応崌丅
* </ul>
*
* 埲壓偺忦審偵崌偆応崌丄falue傪曉偟傑偡 <BR>
* <ul>
* <li>prmStr偺奺暥帤偑丄'0' 乣 '9'偱側偄応崌丅
* </ul>
*
* </PRE>
*
* @return 懳徾暥帤偱偁傟偽 true丄偦傟埲奜偼 false
* @param prmStr
* 僠僃僢僋懳徾暥帤楍
*/
public static boolean isHalfNumber(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 >= '0' && c <= '9') { //敿妏悢帤
} else {
return false;
}
}
return true;
}
/**
* <H3>敿妏塸悢僠僃僢僋.</H3>
*
* <PRE>
*
* 敿妏塸悢偺僠僃僢僋傪偟傑偡丅 <br>
* 懳徾暥帤 丗 悢帤丄塸戝暥帤丄塸彫暥帤乮慡偰敿妏乯 <br>
* 埲壓偺忦審偵崌偆応崌丄true傪曉偟傑偡丅 <br>
* <ul>
* <li>prmStr偑null丄傕偟偔偼挿偝偑0丅
* <li>prmStr偺奺暥帤偑丄'0' 乣 '9'丄'A' 乣 'Z'丄'a' 乣 'z'偺応崌丅
* </ul>
*
* 埲壓偺忦審偵崌偆応崌丄false傪曉偟傑偡丅 <BR>
* <ul>
* <li>prmStr偺奺暥帤偑丄'0' 乣 '9'丄'A' 乣 'Z'丄'a' 乣 'z'偺偄偢傟偱傕側偄応崌丅
* </ul>
*
* </PRE>
*
* @return 懳徾暥帤偱偁傟偽 true丄偦傟埲奜偼 false
* @param prmStr
* 僠僃僢僋懳徾暥帤楍
*/
public static boolean isHalfStroke(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 >= '0' && c <= '9') || //敿妏悢帤
(c >= 'A' && c <= 'Z') || //敿妏塸戝暥帤
(c >= 'a' && c <= 'z')) { //敿妏塸彫暥帤
} else {
return false;
}
}
return true;
}
/**
* <H3>暥帤楍偺僶僀僩悢傪僠僃僢僋偡傞.</H3>
*
* <PRE>
* [null]傕偟偔偼嬻暥帤偺応崌偼丄true傪曉偟傑偡丅
* </PRE>
*
* @param strInput
* 僠僃僢僋懳徾偺暥帤楍
* @param intMaxLength
* 嵟戝僶僀僩悢
* @return boolean 惓偟偗傟偽 true 偦偆偱側偗傟偽 false
*/
public static boolean isLength(String strInput, int intMaxLength) {
int intLen = 0;
if (strInput == null || strInput.length() == 0) {
return true;
}
try {
byte[] bytstr = strInput.getBytes(ENCODING);
intLen = bytstr.length;
} catch (Exception e) {
e.printStackTrace();
}
if (intLen <= intMaxLength) {
return true;
}
return false;
}
/**
* 敿妏悢帤偱丄偐偮巜掕偝傟偨僶僀僩悢埲撪偐傪敾抐偡傞. <BR>
*
* <PRE>
* null傕偟偔偼嬻暥帤偺応崌偼丄true傪曉偟傑偡丅
* 彫悢揰偑懚嵼偡傞応崌偼false傪曉偟傑偡丅
* 儅僀僫僗晞崋偼丄true傪曉偟傑偡丅
*
* 椺)
* 1.1 : false
* -11 : true
* </PRE>
*
* @param strInput
* 僠僃僢僋懳徾偺暥帤楍
* @param intMaxLength
* 嵟戝僶僀僩悢
* @return boolean 巜掕偝傟偨忦審撪側傜偽 true 偦偆偠傖側偗傟偽 false
*/
public static boolean isNumberByte(String strInput, int intMaxLength) {
if (strInput == null || strInput.length() == 0) {
return true;
}
if (!isStringSingle(strInput) || !isNumber(strInput)
|| !isLength(strInput, intMaxLength)) {
return false;
}
return true;
}
/**
* 敿妏偱丄偐偮巜掕偝傟偨僶僀僩悢埲撪偐傪敾抐偡傞. <br>
*
* <PRE>
* null傕偟偔偼嬻暥帤偺応崌偼丄true傪曉偟傑偡丅
* </PRE>
*
* @param strInput
* 僠僃僢僋懳徾偺暥帤楍
* @param intMaxLength
* 嵟戝僶僀僩悢
* @return boolean 巜掕偝傟偨忦審撪側傜偽 true 偦偆偠傖側偗傟偽 false
*/
public static boolean isStringSingleByte(String strInput, int intMaxLength) {
if (strInput == null || strInput.length() == 0) {
return true;
}
if (!isStringSingle(strInput) || !isLength(strInput, intMaxLength)) {
return false;
}
return true;
}
/**
* 慡妏偱丄偐偮巜掕偝傟偨僶僀僩悢埲撪偐傪敾抐偡傞. <br>
*
* <PRE>
* null傕偟偔偼嬻暥帤偺応崌偼丄true傪曉偟傑偡丅
* </PRE>
*
* @param strInput
* 僠僃僢僋懳徾偺暥帤楍
* @param intMaxLength
* 嵟戝僶僀僩悢
* @return boolean 巜掕偝傟偨忦審撪側傜偽 true 偦偆偠傖側偗傟偽 false
*/
public static boolean isString2byteByte(String strInput, int intMaxLength) {
if (strInput == null || strInput.length() == 0) {
return true;
}
if (!isString2byte(strInput) || !isLength(strInput, intMaxLength)) {
return false;
}
return true;
}
/**
* 暥帤楍偑悢抣偺傒偱峔惉偝傟偰偄傞偐傪僠僃僢僋偡傞
*
* <PRE>
* null傕偟偔偼嬻暥帤偺応崌偼丄true傪曉偟傑偡丅
* </PRE>
*
* @param strInput
* 僠僃僢僋懳徾偺暥帤楍
* @return boolean 悢抣偺傒側傜 true 偦偆偱側偗傟偽 false
*/
public static boolean isNumber(String strInput) {
if (strInput == null || strInput.length() == 0) {
return true;
}
if (!isStringSingle(strInput)) {
return false;
}
return true;
}
/**
* 暥帤楍拞偑慡偰敿妏暥帤偱偁傞偐僠僃僢僋偡傞
*
* <PRE>
* null傕偟偔偼嬻暥帤偺応崌偼丄true傪曉偟傑偡丅
* </PRE>
*
* @param strInput
* 僠僃僢僋懳徾偺暥帤楍
* @return boolean 敿妏暥帤偺傒側傜 true 偦偆偱側偗傟偽 false
*/
public static boolean isStringSingle(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 != length) { // 僶僀僩悢偑暥帤悢偲摍偟偔側偄応崌
return false;
}
return true;
}
/**
* 暥帤楍偑敿妏塸悢偺傒偱峔惉偝傟偰偄傞偐傪僠僃僢僋偡傞
*
* <PRE>
* null傕偟偔偼嬻暥帤偺応崌偼丄true傪曉偟傑偡丅
* </PRE>
*
* @param strInput
* 僠僃僢僋懳徾偺暥帤楍
* @return boolean 敿妏塸悢偺傒側傜 true 偦偆偱側偗傟偽 false
*/
public static boolean isAlphabet(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 < 'a' || c > 'z') && // 彫暥帤傾儖僼傽儀僢僩偱側偄
(c < 'A' || c > 'Z') // 戝暥帤傾儖僼傽儀僢僩偱側偄
) {
return false;
}
}
return true;
}
/**
* 暥帤楍拞偑慡偰慡妏暥帤偱偁傞偐僠僃僢僋偡傞
*
* <PRE>
* null傕偟偔偼嬻暥帤偺応崌偼丄true傪曉偟傑偡丅
* </PRE>
*
* @param strInput
* 僠僃僢僋懳徾偺暥帤楍
* @return boolean 慡妏暥帤乮2僶僀僩暥帤乯偺傒側傜 true 偦偆偱側偗傟偽 false
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -