FrmRegularExpressionValidator.aspx |
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> 정규식(정규표현식) 검사?<br />
이메일 : <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
<asp:RegularExpressionValidator ID="valEmail" runat="server" ControlToValidate="txtEmail" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*" ErrorMessage="이메일을 정확히"></asp:RegularExpressionValidator> <br /><br />
<asp:Button ID="btnOK" runat="server" Text="확인" /> </div> </form> </body> </html> |
결과화면 |
[그림33-1] |
CompareValidator 컨트롤을 자바스크립트로 표현한 예제입니다.
FrmRegularExpressionValidator.htm |
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> <script type="text/javascript"> function CheckEmail() { if (check_mail(document.getElementById("txtEmail"))) { alert("OK"); } else { alert("뭐지?"); } }
//[5] 메일주소 검사 function check_mail(cg) { /// <summary> /// 맞으면 true /// </summary> EmailEx1 = /[^@]+@[A-Za-z0-9_\-]+\.[A-Za-z]+/; EmailEx2 = /[^@]+@[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-] +\.[A-Za-z]+/; EmailEx3 = /[^@]+@[A-Za-z0-9_\-]+\.[A-Za-z0-9_\-] +\.[A-Za-z0-9_\-]+\.[A-Za-z]+/;
if (EmailEx1.test(cg.value)) return true; if (EmailEx2.test(cg.value)) return true; if (EmailEx3.test(cg.value)) return true;
return false; } </script> </head> <body> 이메일 : <input type="text" id="txtEmail" /> <br /> <input type="button" value="체크" onclick="CheckEmail()" /> </body> </html> |
결과화면 |
|
FrmRegularExpressionValidator.aspx
FrmRegularExpressionValidator.aspx.cs
FrmRegularExpressionValidator.htm
'ASP.NET' 카테고리의 다른 글
35.C# ASP.NET - ValidationSummary [ 유효성검사컨트롤 ] (0) | 2009.10.13 |
---|---|
34.C# ASP.NET - CustomValidator [ 유효성검사컨트롤 ] (0) | 2009.10.13 |
32.C# ASP.NET - CompareValidator [ 유효성검사컨트롤 ] (0) | 2009.10.13 |
31.C# ASP.NET - RangeValidator [ 유효성검사컨트롤 ] (0) | 2009.10.13 |
30.C# ASP.NET - RequiredFieldValidator [ 유효성검사컨트롤 ] (0) | 2009.10.13 |
Comments