.NET Framework

C# 정규식 예제

Sunny's 2010. 10. 22. 19:38

static void Main(string[] args)
{
        string str = "abcwDW2";

        // 날짜 형식 "yyyy-MM-dd"
        string sParttern = @"^(19[0-9]{2}|2[0-9]{3})-(0[1-9]|1[012])-([123]0|[012][1-9]|31)$";  

        // 숫자와 영문 소문자,대문자만 입력가능합니다.(글자제한100)");
        //string sParttern = @"^[0-9a-zA-Z]{1,100}$";

        Regex regex = new System.Text.RegularExpressions.Regex(sParttern );

        Boolean ismatch = regex.IsMatch(str);
        if (!ismatch)
        {
            Console.WriteLine("날짜 형식이 아닙니다.");
        }
}




영문 소문자, 대문자와 숫자만 가능하도록 하는 유효성 체크에 사용될 만한 예제입니다.