regularexpression1.aspx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <%@ Page Language="C#" AutoEventWireup="True" %>
  2. <html>
  3. <head>
  4. <script runat="server">
  5. void ValidateBtn_Click(Object sender, EventArgs e)
  6. {
  7. if (Page.IsValid)
  8. {
  9. lblOutput.Text = "Page is Valid!";
  10. }
  11. else
  12. {
  13. lblOutput.Text = "Page is InValid! :-(";
  14. }
  15. }
  16. </script>
  17. </head>
  18. <body>
  19. <h3>RegularExpressionValidator Example</h3>
  20. <p>
  21. <form runat="server">
  22. <table bgcolor="#eeeeee" cellpadding="10">
  23. <tr valign="top">
  24. <td colspan="3">
  25. <asp:Label ID="lblOutput"
  26. Text="Enter a 5 digit zip code"
  27. runat="server"/>
  28. </td>
  29. </tr>
  30. <tr>
  31. <td colspan="3">
  32. <b>Personal Information</b>
  33. </td>
  34. </tr>
  35. <tr>
  36. <td align="right">
  37. Zip Code:
  38. </td>
  39. <td>
  40. <asp:TextBox id="TextBox1"
  41. runat="server"/>
  42. </td>
  43. <td>
  44. <asp:RegularExpressionValidator id="RegularExpressionValidator1"
  45. ControlToValidate="TextBox1"
  46. ValidationExpression="\d{5}"
  47. Display="Static"
  48. ErrorMessage="Zip code must be 5 numeric digits"
  49. EnableClientScript="True"
  50. runat="server"/>
  51. </td>
  52. </tr>
  53. <tr>
  54. <td></td>
  55. <td>
  56. <asp:Button text="Validate"
  57. OnClick="ValidateBtn_Click"
  58. runat=server />
  59. </td>
  60. <td></td>
  61. </tr>
  62. </table>
  63. </form>
  64. </body>
  65. </html>