| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using Microsoft.AspNetCore.Mvc;
- using System.Text.RegularExpressions;
- using System.Xml.Serialization;
- namespace economy.Helpers
- {
- public class Common
- {
- // XML 데이터 직렬화
- public static async Task<T> ParseXmlDataAsync<T>(string xmlData) where T : class
- {
- var serializer = new XmlSerializer(typeof(T));
- using (var reader = new StringReader(xmlData))
- {
- return await Task.Run(() => (T)serializer.Deserialize(reader));
- }
- }
- // 시작 번호 조회
- public static int CalcListNumber(int total, int page, int perPage)
- {
- return (total - ((page - 1) * perPage));
- }
- // 천 단위 구분 형식으로 변환
- public static string NumberFormat(string s, string format = "N0")
- {
- if (int.TryParse(s, out int clprValue))
- {
- s = clprValue.ToString(format);
- }
- if (double.TryParse(s, out double doubleValue))
- {
- return doubleValue.ToString(format);
- }
- if (decimal.TryParse(s, out decimal decimalValue))
- {
- return decimalValue.ToString(format);
- }
- return s;
- }
- // 문자열 형태의 날짜를 포맷 형식으로 변환
- public static string StringToDateFormat(string s, string format = "yyyy-MM-dd")
- {
- return DateTime.ParseExact(s, "yyyyMMdd", null).ToString(format);
- }
- // 도메인 형식 여부
- public static bool IsDomain(string input)
- {
- return Regex.IsMatch(input, @"^[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,}$");
- }
- // IPv4 형식 여부
- public static bool IsIPv4(string input)
- {
- return Regex.IsMatch(input, @"^(\d{1,3}\.){3}\d{1,3}$");
- }
- // IPv6 형식 여부
- public static bool IsIPv6(string input)
- {
- return Regex.IsMatch(input, @"^([0-9a-fA-F]{1,4}:){1,7}[0-9a-fA-F]{1,4}(/([0-9]|[1-9][0-9]|1[0-1][0-9]|12[0-8]))?$");
- }
- }
- }
|