首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-03-29 06:18:43
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
推荐阅读
中端手機芯片有哪些
中端手機芯片有哪些
中端手機芯片有哪些?對于大多數人來講,買手機不需要太貴,隻要合适就可以了,因此一些2000元左右的性能小鋼炮就成了不錯的選擇對此,筆者剛好也挑了四款2000元左右手機,這四款産品不敢說性能比肩旗艦産品,但至少不會差太多,而且每款都有不錯性價...
2026-03-29
以純a21适合年齡
以純a21适合年齡
我記得初中時還跟媽媽說過:我穿衣服就隻穿以純這個牌子,别的不要買了!嘻嘻嘻,你能猜得到今天的主題嘛?對,就是咱們國産快時尚品牌【以純A21】—真人試穿測評!會從firstlook、官方試穿、小編試穿、搭配推薦四方面給你解讀哦!先來一發以純的...
2026-03-29
pdf文件轉換成txt詳細教程
pdf文件轉換成txt詳細教程
在我們工作中或者學習中總會有各種文件要處理,pdf文件應該是我們最常用的一種文件了,這種文件有很多的優點,它傳輸起來很方便,也非常便于觀看,而且還不容易出現版式錯誤的問題,所以我們也很喜歡用pdf文件來處理工作内容。但是pdf文件也有一些不...
2026-03-29
删除windows的用戶賬戶
删除windows的用戶賬戶
本文主要解決以下兩種問題:1、未使用administrator賬戶的個人電腦,在個人賬戶權限出現故障的時候,可以删除個人賬戶的用戶配置,除桌面文件外,不會删除個人文件,也不會影響該賬戶下軟件的正常使用;2、共享的多用戶服務器,當用戶操作不當...
2026-03-29
mc手機版怎麼開副手
mc手機版怎麼開副手
mc手機版怎麼開副手?在我的世界1.9版本以前,玩家的史蒂夫雖然有兩隻手,但是基本都隻是右手在用,左手貌似沒出啥力氣但是1.9版本以後史蒂夫的左手也被解放出來了,今天小編就來聊一聊關于mc手機版怎麼開副手?接下來我們就一起去研究一下吧!mc...
2026-03-29
Copyright 2023-2026 - www.tftnews.com All Rights Reserved