首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-06-06 22:21:44
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
推荐阅读
手機左上角出現ks是什麼意思啊
手機左上角出現ks是什麼意思啊
手機左上角出現ks是什麼意思啊?ks指每秒鐘消耗的流量,k就是流量的單位若手機使用移動數據上網速度慢,請按以下方法解決:,我來為大家講解一下關于手機左上角出現ks是什麼意思啊?跟着小編一起來看一看吧!手機左上角出現ks是什麼意思啊ks指每秒...
2026-06-06
oppor9s手機搬家怎麼使用
oppor9s手機搬家怎麼使用
雖然如今手機市場中發布的新機很多,但是大多數用戶卻是不願意換機的,這是為什麼呢?其中一個主要的原因是舊手機中存儲了太多珍貴的資料,換到新機上或多或少都會丢失一些,而且數據導來導去非常麻煩。針對這一問題昨日發布的新機OPPOR9s就給出了很好...
2026-06-06
1060遊戲主機值得入手嗎
1060遊戲主機值得入手嗎
中高端遊戲組裝電腦清單推薦:今天電腦配置網為大家帶來一套中高端遊戲組裝電腦清單,該配置可以在1080p甚至2k分辨率下暢玩各類大型遊戲,包括絕地求生、使命召喚、GTA5、Apex英雄、孤島驚魂、守望先鋒、古墓麗影……先來看看處理器。在說到高...
2026-06-06
5款需要低調使用的黑科技電腦軟件
5款需要低調使用的黑科技電腦軟件
優秀的電腦軟件能極大提高我們的工作效率,今天我就給大家分享6款非常不錯的電腦軟件,希望對你有所幫助。01*AID64-查參數聽很多人說,魯大師是一款查電腦參數的好工具,實際情況真的是這樣嗎?反正我隻是用來跑分的。查看電腦參數,我覺得還是得用...
2026-06-06
s5雲頂之弈亞索陣容最新版本
s5雲頂之弈亞索陣容最新版本
在11.15版本中,各個棋子身上的羁絆越來越多,各種各樣的套路也層出不窮,今天我要給大家推薦的是當前版本的T0陣容。在這套陣容中,4黑夜使者為主要羁絆,亞索為主c。陣容組成及羁絆:陣容組成:亞索,刀妹,泰坦,豬妹,盲僧,皎月,武器,芮爾。亞...
2026-06-06
Copyright 2023-2026 - www.tftnews.com All Rights Reserved