惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
S
SegmentFault 最新的问题
罗磊的独立博客
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
DataBreaches.Net
F
Fortinet All Blogs
TaoSecurity Blog
TaoSecurity Blog
D
Docker
C
Cybersecurity and Infrastructure Security Agency CISA
K
Kaspersky official blog
宝玉的分享
宝玉的分享
腾讯CDC
Google Online Security Blog
Google Online Security Blog
Recorded Future
Recorded Future
T
The Exploit Database - CXSecurity.com
T
The Blog of Author Tim Ferriss
V
V2EX
S
Securelist
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
C
CERT Recently Published Vulnerability Notes
A
Arctic Wolf
Scott Helme
Scott Helme
L
LINUX DO - 热门话题
Y
Y Combinator Blog
P
Proofpoint News Feed
T
Tor Project blog
AWS News Blog
AWS News Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
T
Threat Research - Cisco Blogs
B
Blog
Attack and Defense Labs
Attack and Defense Labs
L
Lohrmann on Cybersecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
N
News and Events Feed by Topic
博客园 - 司徒正美
H
Help Net Security
C
Cisco Blogs
C
Check Point Blog
S
Secure Thoughts

博客园 - niuyy

博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 博文阅读密码验证 - 博客园 .net 中用到excel中,检索COM类工厂中的CLSID为{000 24500-0000-0000-C000-000000000046}的组件时失败 客户端获取传递的参数 SQL语句中,插入单引号、添加、删除字段 JS给RadioButtonList赋值 在SQL2000中不显示系统表及系统文件 Embed标签详解 可以拖动,关闭的DIV组合 获取计算机用户名 浏览器字体变小 学习小技巧 ComBox 绑定数据库 C# 读取文本文件 字符编码 ComboBox与其他控件的联动 在.net中应用事务 数据库索引应用(ms-sql) 开发人员组要注意的网站
C# 在.cs文件中使用正则表达式
niuyy · 2007-08-21 · via 博客园 - niuyy

页面代码:

 1 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="IsNumeric.aspx.cs" Inherits="IsNumeric" %>
 2 
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 4 
 5 <html xmlns="http://www.w3.org/1999/xhtml" >
 6 <head runat="server">
 7     <title>无标题页</title>
 8 </head>
 9 <body>
10     <form id="form1" runat="server">
11     <div>
12         <asp:Label ID="Label1" runat="server" Text="正整数验证"></asp:Label>
13         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
14         <asp:Button ID="Button1" runat="server" Text="正整数验证" OnClick="Button1_Click" />
15         <br />
16         <br />
17         <br />
18         <br />
19         <asp:Label ID="Label2" runat="server" Text="钱币验证"></asp:Label>
20         <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
21         
22         <asp:Button ID="Button2" runat="server" Text="钱币验证" OnClick="Button2_Click" /></div>
23     </form>
24 </body>
25 </html>

后台代码:

 1 using System;
 2 using System.Data;
 3 using System.Configuration;
 4 using System.Collections;
 5 using System.Web;
 6 using System.Web.Security;
 7 using System.Web.UI;
 8 using System.Web.UI.WebControls;
 9 using System.Web.UI.WebControls.WebParts;
10 using System.Web.UI.HtmlControls;
11 using System.Text.RegularExpressions;
12 
13 public partial class IsNumeric : System.Web.UI.Page
14 {
15     protected void Page_Load(object sender, EventArgs e)
16     {
17 
18     }
19 
20     protected void Button1_Click(object sender, EventArgs e)
21     {
22        string value =TextBox1.Text;
23        bool Istrue = isNumeric(value);
24        if (Istrue)
25        {
26           
27            Response.Write("<script language='javascript'  type='text/javascript'> alert('你输入的数是整数!') </script>");
28        }
29        else
30        {
31            Response.Write("<script language='javascript'  type='text/javascript'> alert('你输入的数不是整数!') </script>");
32        }
33 
34     }
35     protected void Button2_Click(object sender, EventArgs e)
36     {
37         string value = TextBox2.Text;
38         bool Istrue = isMoney(value);
39         if (Istrue)
40         {
41 
42             Response.Write("<script language='javascript'  type='text/javascript'> alert('你输入的数是货币形式!') </script>");
43         }
44         else
45         {
46             Response.Write("<script language='javascript'  type='text/javascript'> alert('你输入的数不是不是货币形式!') </script>");
47         }
48     }
49 
50     private static bool isNumeric(string itemValue)
51     {
52         return (IsRegEx("^\\d+$", itemValue));//正整数
53 
54     }
55     private static bool isMoney(string itemValue)
56     {
57         return (IsRegEx("^[0-9]+(\\.[0-9]{1,2})?$", itemValue));
58     }
59 
60     private static bool IsRegEx(string regExValue, string itemValue)
61     {
62 
63         try
64         {
65             Regex regex = new System.Text.RegularExpressions.Regex(regExValue);
66             if (regex.IsMatch(itemValue)) return true;
67             else return false;
68         }
69         catch (Exception)
70         {
71             return false;
72         }
73         finally
74         {
75         }
76     }
77     
78 }
79