본문 바로가기
백엔드기술/개발언어

C# 정규식 예제

by RevFactory 2009. 3. 17.

static void Main(string[] args)
{
        string str = "abcwDW2";
        Regex regex = new System.Text.RegularExpressions.Regex(@"^[0-9a-zA-Z]{1,100}$");

        Boolean ismatch = regex.IsMatch(str);
        if (!ismatch)
        {
            Console.WriteLine("숫자와 영문 소문자,대문자만 입력가능합니다.(글자제한100)");
        }
}


영문 소문자, 대문자와 숫자만 가능하도록 하는 유효성 체크에 사용될 만한 예제입니다.
글자수 제한도 저렇게 하는군요^^