spc-kiosk-pb/Kiosk/Common/SPC.Kiosk.Common/Functions/CommonChecker.cs

672 lines
20 KiB
C#
Raw Permalink Normal View History

2019-06-16 05:12:09 +00:00

namespace SPC.Kiosk.Common
{
public static class CommonChecker
{
#region ASCII
/// <summary>
/// 문자,문자열이 모두 영문인지 체크
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static bool rIsAlpa(this string _inString)
{
bool result = false;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToLower().ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsAlpa();
if (!result) break;
}
}
}
catch
{
result = false;
}
return result;
}
/// <summary>
/// 문자가 영문자인지 체크
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static bool rIsAlpa(this char _inChar)
{
return ((int)_inChar > 0x40 && (int)_inChar < 0x5B
|| (int)_inChar > 0x60 && (int)_inChar < 0x7B);
}
/// <summary>
/// 문자,문자열이 모두 영문 대문자인지 체크
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static bool rIsBigAlpa(this string _inString)
{
bool result = false;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsBigAlpa();
if (!result) break;
}
}
}
catch
{
result = false;
}
return result;
}
/// <summary>
/// 문자가 대문자인지 체크
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static bool rIsBigAlpa(this char _inChar)
{
return (int)_inChar > 0x40 && (int)_inChar < 0x5B;
}
/// <summary>
/// 문자열이 모두 소문자인지 체크
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static bool rIsSmallAlpa(this string _inString)
{
bool result = false;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsSmallAlpa();
if (!result) break;
}
}
}
catch
{
result = false;
}
return result;
}
/// <summary>
/// 문자열이 숫자인지 체크
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static bool rIsNum(this string _inString)
{
bool result = false;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsNum();
if (!result) break;
}
}
}
catch
{
result = false;
}
return result;
}
/// <summary>
/// 문자가 숫자인지 체크
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static bool rIsNum(this char _inChar)
{
try
{
return ((int)_inChar > 0x2F && (int)_inChar < 0x3A);
}
catch
{
return false;
}
}
/// <summary>
/// 문자가 영문 소문자인지 체크
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static bool rIsSmallAlpa(this char _inChar)
{
return (int)_inChar > 0x60 && (int)_inChar < 0x7B;
}
/// <summary>
/// 문자열이 영문대소문자 또는 숫자로 인지 체크
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static bool rIsAlpaNum(this string _inString)
{
bool result = false;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsAlpaNum();
if (!result) break;
}
}
}
catch
{
result = false;
}
return result;
}
/// <summary>
/// 문자가 영문자 또는 숫자인지 체크
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static bool rIsAlpaNum(this char _inChar)
{
return ((int)_inChar > 0x60 && (int)_inChar < 0x7B)
|| ((int)_inChar > 0x40 && (int)_inChar < 0x5B)
|| ((int)_inChar > 0x2F && (int)_inChar < 0x3A);
}
/// <summary>
/// 문자열이 Hex문자열인지 체크
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static bool rIsHexaNum(this string _inString)
{
bool result = false;
try
{
if (_inString != null && _inString.Length > 0)
{
if (_inString.Length % 2 > 0)
{
result = false;
}
else
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsHexaNum();
if (!result) break;
}
}
}
}
catch
{
result = false;
}
return result;
}
/// <summary>
/// 문자가 Hex문자에 속하는지 체크
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static bool rIsHexaNum(this char _inChar)
{
return ((int)_inChar > 0x60 && (int)_inChar < 0x67)
|| ((int)_inChar > 0x40 && (int)_inChar < 0x47)
|| ((int)_inChar > 0x2F && (int)_inChar < 0x3A);
}
/// <summary>
/// 문자열 Bit형(0,1)인지 체크
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static bool rIsBitNum(this string _inString)
{
bool result = false;
try
{
if (_inString != null && _inString.Length > 0)
{
if (_inString.Length % 8 > 0)
{
result = false;
}
else
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsBitNum();
if (!result) break;
}
}
}
}
catch
{
result = false;
}
return result;
}
/// <summary>
/// 문자가 Bit형(0,1)인지 체크
/// </summary>
/// <param name="_inChar"></param>
/// <returns></returns>
public static bool rIsBitNum(this char _inChar)
{
return (_inChar.Equals((char)0x30) || _inChar.Equals((char)0x31));
}
#endregion
#region
/// <summary>
/// 문자열내 특정문자 갯수
/// </summary>
/// <param name="_inString"></param>
/// <param name="_inChar"></param>
/// <returns></returns>
public static int rCountChar(this string _inString, char _inChar)
{
return _inString.rCountChar(_inChar, CodeType.Default);
}
/// <summary>
/// 인코딩 된 문자열내 특정문자 갯수
/// </summary>
/// <param name="_inString"></param>
/// <param name="_inChar"></param>
/// <param name="_CodeType"></param>
/// <returns></returns>
public static int rCountChar(this string _inString, char _inChar, CodeType _CodeType)
{
int result = 0;
try
{
foreach (char _aChar in _inString.rToEncChar(_CodeType))
{
if (_aChar.Equals(_inChar)) result++;
}
}
catch
{
result = 0;
}
return result;
}
/// <summary>
/// 문자열내 특정문자 갯수
/// </summary>
/// <param name="_inString"></param>
/// <param name="_inChar"></param>
/// <returns></returns>
public static int rCountChar(this string _inString, string _inChar)
{
return _inString.rCountChar(_inChar, CodeType.Default);
}
/// <summary>
/// 문자열내 특정문자 갯수
/// </summary>
/// <param name="_inString"></param>
/// <param name="_inChar"></param>
/// <param name="_CodeType"></param>
/// <returns></returns>
public static int rCountChar(this string _inString, string _inChar, CodeType _CodeType)
{
int result = 0;
try
{
foreach (char _aChar in _inString.rToEncChar(_CodeType))
{
if (_aChar.Equals(_inChar.ToCharArray()[0])) result++;
}
}
catch
{
result = 0;
}
return result;
}
/// <summary>
/// Byte배열내에 특정 바이트 갯수
/// </summary>
/// <param name="_inBytes"></param>
/// <param name="_inByte"></param>
/// <returns></returns>
public static int rCountChar(this byte[] _inBytes, byte[] _inByte)
{
int result = 0;
try
{
foreach (byte _aByte in _inBytes)
{
if (_aByte.Equals(_inByte)) result++;
}
}
catch
{
result = 0;
}
return result;
}
/// <summary>
/// 문자열내 대문자 숫자 갯수
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static int rCountBigAlpa(this string _inString)
{
int result = 0;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsBigAlpa() ? result + 1 : result;
}
}
}
catch
{
result = 0;
}
return result;
}
/// <summary>
/// 문자열내 소문자 갯수
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static int rCountSmallAlpa(this string _inString)
{
int result = 0;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsSmallAlpa() ? result + 1 : result;
}
}
}
catch
{
result = 0;
}
return result;
}
/// <summary>
/// 문자열내 숫자 갯수
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static int rCountNumber(this string _inString)
{
int result = 0;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsNum() ? result + 1 : result;
}
}
}
catch
{
result = 0;
}
return result;
}
/// <summary>
/// 문자열내 영문자 또는 숫자 갯수
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static int rCountAlpaNum(this string _inString)
{
int result = 0;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsAlpaNum() ? result + 1 : result;
}
}
}
catch
{
result = 0;
}
return result;
}
/// <summary>
/// 문자열내 특수문자 숫자
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static int rCountSpecialChar(this string _inString)
{
int result = 0;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsAlpaNum() || (int)getChar > 0x92 ? result : result + 1;
}
}
}
catch
{
result = 0;
}
return result;
}
/// <summary>
/// 문자열내 최대 동일문자 반복숫자
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static int rCountMaxRepeat(this string _inString)
{
int result = 0;
int count = 0;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToCharArray();
char lastChar = ' ';
foreach (char getChar in getChars)
{
if (getChar != lastChar)
{
if (count > result) result = count;
count = 1;
lastChar = getChar;
}
else
{
count++;
}
}
if (count > result) result = count;
}
}
catch
{
result = 0;
}
return result;
}
#endregion
#region (,)
/// <summary>
/// 문자열이 정수형인지 체크
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static bool rIsPlusInteger(this string _inString)
{
bool result = false;
try
{
if (_inString != null && _inString.Length > 0)
{
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsNum();
if (!result) break;
}
}
}
catch
{
result = false;
}
return result;
}
/// <summary>
/// 문자열이 정수형인지 체크
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static bool rIsInteger(this string _inString)
{
bool result = false;
try
{
if (_inString != null && _inString.Length > 0)
{
if (_inString.Length > 1 && _inString.StartsWith("-")) _inString = _inString.Substring(1);
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsNum();
if (!result) break;
}
}
}
catch
{
result = false;
}
return result;
}
/// <summary>
/// 문자열이 실수형인지 체크
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static bool rIsFloat(this string _inString)
{
bool result = false;
try
{
if (_inString != null && _inString.Length > 0)
{
if (_inString.Length > 1 && _inString.StartsWith("-")) _inString = _inString.Substring(1);
int _firstPoint = _inString.IndexOf('.');
if (_inString.IndexOf('.', _firstPoint + 1) == -1)
{
_inString = _inString.Replace(".", "");
char[] getChars = _inString.ToCharArray();
foreach (char getChar in getChars)
{
result = getChar.rIsNum();
if (!result) break;
}
}
}
}
catch
{
result = false;
}
return result;
}
#endregion
#region
/// <summary>
/// 암호 등급[
/// 8자이하 0,
/// 반복문자가 있는 경우는 -1 Level,
/// 연속으로 동일 문자가 있으면 0,
/// 형태수 + 8자이상이면 4자마다 1식추가
/// ]
/// </summary>
/// <param name="_inString"></param>
/// <returns></returns>
public static int rPassWordLevel(this string _inString)
{
int level = 0;
level += _inString.rCountBigAlpa() > 0 ? 1 : 0;
level += _inString.rCountSmallAlpa() > 0 ? 1 : 0;
level += _inString.rCountSpecialChar() > 0 ? 1 : 0;
level += _inString.rCountNumber() > 0 ? 1 : 0;
level = _inString.Length > 7 ? level + _inString.Length / 4 - 1 : 0;
level = _inString.rCountMaxRepeat() > 1 ? level - 1 : level;
return level;
}
#endregion
}
}