RegularExpressionValidator.ValidationExpression プロパティ
アセンブリ: System.Web.Mobile (system.web.mobile.dll 内)

Dim instance As RegularExpressionValidator Dim value As String value = instance.ValidationExpression instance.ValidationExpression = value
[BindableAttribute(true)] public: property String^ ValidationExpression { String^ get (); void set (String^ value); }
/** @property */ public String get_ValidationExpression () /** @property */ public void set_ValidationExpression (String value)
public function get ValidationExpression () : String public function set ValidationExpression (value : String)
検証の基準になるように割り当てられた正規表現。



Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


RegularExpressionValidator.ValidationExpression プロパティ
アセンブリ: System.Web (system.web.dll 内)

Dim instance As RegularExpressionValidator Dim value As String value = instance.ValidationExpression instance.ValidationExpression = value
[ThemeableAttribute(false)] public: property String^ ValidationExpression { String^ get (); void set (String^ value); }
/** @property */ public String get_ValidationExpression () /** @property */ public void set_ValidationExpression (String value)
public function get ValidationExpression () : String public function set ValidationExpression (value : String)
フィールドの書式の検証に使用する正規表現を指定する文字列。既定値は String.Empty です。


このプロパティを使用して、社会保障番号、電子メール アドレス、電話番号、郵便番号などの予測可能な文字列をチェックするために使用するパターンを指定します。
正規表現の詳細については、「.NET Framework の正規表現」を参照してください。
![]() |
---|
部分一致式で問題が発生した場合は、式を "^(" と ")$" で囲んでみてください。たとえば、"a|ab" の場合は、"^(a|ab)$" のようにします。 |
このプロパティを、テーマまたはスタイル シート テーマを使用して設定することはできません。詳細については、ThemeableAttribute、ASP.NET のテーマとスキンの概要 の各トピックを参照してください。

ValidationExpression プロパティを使用して、5 桁の数値フィールドを検証する方法を次の例に示します。Button コントロールがクリックされると、OnClick イベント ハンドラによって Page の IsValid プロパティがチェックされ、TextBox 内のテキストが正規表現と一致しているかどうかが判断されます。
<%@ Page Language="VB" AutoEventWireup="True" %> <html> <head> <script runat="server"> Sub ValidateBtn_Click(sender As Object, e As EventArgs) If Page.IsValid Then lblOutput.Text = "Page is Valid." Else lblOutput.Text = "Page is InValid." End If End Sub </script> </head> <body> <h3>RegularExpressionValidator Example</h3> <p> <form runat="server"> <table bgcolor="#eeeeee" cellpadding="10"> <tr valign="top"> <td colspan="3"> <asp:Label ID="lblOutput" Text="Enter a 5 digit zip code" runat="server"/> </td> </tr> <tr> <td colspan="3"> <b>Personal Information</b> </td> </tr> <tr> <td align="right"> Zip Code: </td> <td> <asp:TextBox id="TextBox1" runat="server"/> </td> <td> <asp:RegularExpressionValidator id="RegularExpressionValidator1" ControlToValidate="TextBox1" ValidationExpression="\d{5}" Display="Static" ErrorMessage="Zip code must be 5 numeric digits" EnableClientScript="False" runat="server"/> </td> </tr> <tr> <td></td> <td> <asp:Button text="Validate" OnClick="ValidateBtn_Click" runat=server /> </td> <td></td> </tr> </table> </form> </body> </html>
<%@ Page Language="C#" AutoEventWireup="True" %> <html> <head> <script runat="server"> void ValidateBtn_Click(Object sender, EventArgs e) { if (Page.IsValid) { lblOutput.Text = "Page is Valid."; } else { lblOutput.Text = "Page is InValid."; } } </script> </head> <body> <h3>RegularExpressionValidator Example</h3> <p> <form runat="server"> <table bgcolor="#eeeeee" cellpadding="10"> <tr valign="top"> <td colspan="3"> <asp:Label ID="lblOutput" Text="Enter a 5 digit zip code" runat="server"/> </td> </tr> <tr> <td colspan="3"> <b>Personal Information</b> </td> </tr> <tr> <td align="right"> Zip Code: </td> <td> <asp:TextBox id="TextBox1" runat="server"/> </td> <td> <asp:RegularExpressionValidator id="RegularExpressionValidator1" ControlToValidate="TextBox1" ValidationExpression="\d{5}" Display="Static" ErrorMessage="Zip code must be 5 numeric digits" EnableClientScript="False" runat="server"/> </td> </tr> <tr> <td></td> <td> <asp:Button text="Validate" OnClick="ValidateBtn_Click" runat=server /> </td> <td></td> </tr> </table> </form> </body> </html>
<%@ Page Language="JScript" AutoEventWireup="True" %> <html> <head> <script runat="server"> function ValidateBtn_Click(sender : Object, e : EventArgs) { if (Page.IsValid) { lblOutput.Text = "Page is Valid."; } else { lblOutput.Text = "Page is InValid."; } } </script> </head> <body> <h3>RegularExpressionValidator Example</h3> <p> <form runat="server"> <table bgcolor="#eeeeee" cellpadding="10"> <tr valign="top"> <td colspan="3"> <asp:Label ID="lblOutput" Text="Enter a 5 digit zip code" runat="server"/> </td> </tr> <tr> <td colspan="3"> <b>Personal Information</b> </td> </tr> <tr> <td align="right"> Zip Code: </td> <td> <asp:TextBox id="TextBox1" runat="server"/> </td> <td> <asp:RegularExpressionValidator id="RegularExpressionValidator1" ControlToValidate="TextBox1" ValidationExpression="\d{5}" Display="Static" ErrorMessage="Zip code must be 5 numeric digits" EnableClientScript="False" runat="server"/> </td> </tr> <tr> <td></td> <td> <asp:Button text="Validate" OnClick="ValidateBtn_Click" runat=server /> </td> <td></td> </tr> </table> </form> </body> </html>

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- RegularExpressionValidator.ValidationExpressionのページへのリンク