首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-05-07 13:45:23
C#編程正則表達式驗證數字和字母

c語言正則表達式怎麼寫(源代碼C編程正則表達式驗證數字和字母)1

程序界面

源代碼:

using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Text.RegularExpressions; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { string str = textBox1.Text; if(isyz1(str)) { MessageBox.Show("輸入正确","提示"); } else { MessageBox.Show("輸入有誤,請重新輸入", "提示"); } } private void button3_Click(object sender, EventArgs e) { string str = textBox3.Text; if (isyz3(str)) { MessageBox.Show("輸入正确", "提示"); } else { MessageBox.Show("輸入有誤,請重新輸入", "提示"); } } private void button2_Click(object sender, EventArgs e) { string str = textBox2.Text; if (isyz2(str)) { MessageBox.Show("輸入正确", "提示"); } else { MessageBox.Show("輸入有誤,請重新輸入", "提示"); } } private void button4_Click(object sender, EventArgs e) { string str = textBox4.Text; if (isyz4(str)) { MessageBox.Show("輸入正确", "提示"); } else { MessageBox.Show("輸入有誤,請重新輸入", "提示"); } } private void button5_Click(object sender, EventArgs e) { string str = textBox5.Text; if (isyz5(str)) { MessageBox.Show("輸入正确", "提示"); } else { MessageBox.Show("輸入有誤,請重新輸入", "提示"); } } //驗證非0正整數 public bool isyz1(string sz) { return Regex.IsMatch(sz, @"^\ ?[1-9][0-9]*$"); } //驗證非0負整數 public bool isyz3(string sz) { return Regex.IsMatch(sz, @"^\-[1-9][0-9]*$"); } //驗證大寫字母 public bool isyz2(string sz) { return Regex.IsMatch(sz, @"^[A-Z] $"); } //驗證小寫字母 public bool isyz4(string sz) { return Regex.IsMatch(sz, @"^[a-z] $"); } public bool isyz5(string sz) { return Regex.IsMatch(sz, @"^[A-Za-z] $"); } } }

結語:

熟練掌握正則表達式數字和字母的驗證。

喜歡的請關注、收藏!

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
推荐阅读
dxomark手機前10
dxomark手機前10
DxOMark測試已成為評估智能手機攝像性能的一個經典測試,即使很多手機廠商的發布會,也都會拿DxOMark評分來說明自家手機的攝像性能如何了得。而其實手機攝像性能并不是DxOMark最開始評測的領域,當然,它也不會成為最後的領域,現在Dx...
2026-05-07
會議紀要模闆xls
會議紀要模闆xls
↓↓↓完整版點擊官方小程序去91智庫官網獲取↓↓↓找優質資料文檔,就要來搜索91智庫網(91zk.wang)篇幅有限,91智庫網還給大家整理了非常系統的文檔工具包,去官網搜索下載,
2026-05-07
excel彙總表篩選
excel彙總表篩選
在工作中我們需要把外部的數據導入到excel中,一般導入後都是堆積在一起的,我們要使用某一數據的時候需要手動輸入,比較麻煩。所以我們來看一下當我們把内容導入到excel中時我們想把内容區分開來并放到相對于的表格中,我們一般是複制過去,這樣不...
2026-05-07
羅技cc3500e怎麼調攝像頭
羅技cc3500e怎麼調攝像頭
在網絡發展如此迅速的當今時代,視頻會議系統已經成了大部分企業、公司的标準配置,依靠視頻會議,可以使身在不同地點的工作夥伴既可以聽到對方的聲音,又能看到對方的形象,同時還能看到對方會議室的場景以及在會議中展示的實物、圖片、表格、文件等,“縮短...
2026-05-07
吳磊全部代言品牌
吳磊全部代言品牌
真3D極緻畫面,無縫大世界,網易頂級品質旗艦《天下》手遊明日全平台開啟零門檻暢玩,預下載現已全面開放。昨日《天下》手遊官方正式宣布由國民弟弟吳磊代言,吳磊将以太虛觀小師弟身份初臨大荒攜手網易遊戲大玩家丁磊組建“上天陪玩團”,與全天下玩家樂享...
2026-05-07
Copyright 2023-2026 - www.tftnews.com All Rights Reserved