首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-08-01 22:20:57
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
推荐阅读
華為手機看視頻模糊怎麼辦
華為手機看視頻模糊怎麼辦
華為手機看視頻模糊怎麼辦?應該是手機開啟了智能分辨率造成的,這個功能很多人不知道,有時候打開了就會出現看視頻模糊的問題,今天小編就來聊一聊關于華為手機看視頻模糊怎麼辦?接下來我們就一起去研究一下吧!華為手機看視頻模糊怎麼辦應該是手機開啟了智...
2026-08-01
斷路器規格含義
斷路器規格含義
最近後台有許多用戶都給小編留言想要了解的内容,那麼這兩周我們暫時暫停問答互動,分享些電工朋友的需求,這篇是有電工夥伴在給小編留言希望了解下關于斷路器的主要一些技術參數含義。大家看看是不是自己也想要了解的,如果你有其他想要小編分享的内容,給我...
2026-08-01
華為相冊功能大全
華為相冊功能大全
華為相冊功能大全?1.照片拼圖打開圖庫-發現-拼圖創作,選擇2-9張圖片,點擊開始制作,選擇喜歡的邊框樣式,進行平台制作,點擊右上角保存符号,即可保存到拼圖相冊,我來為大家科普一下關于華為相冊功能大全?下面希望有你要的答案,我們一起來看看吧...
2026-08-01
北京工業大學軟件工程排名
北京工業大學軟件工程排名
目前國内很多大公司正在忙着秋季校園招聘,在各大公司校招崗位中,研發、算法類崗位還是比較多的,尤其在互聯網類公司是主流招聘崗位。而這類熱門崗位都需要有熟練的編程能力,比較适合軟件工程、計算機等專業畢業生。相對來說,軟件開發等互聯網類人才想找個...
2026-08-01
公務員行測地理基礎知識
公務員行測地理基礎知識
(注:山東省考備考個人筆記,僅供參考,有遺漏或存疑的地方歡迎指正;),
2026-08-01
Copyright 2023-2026 - www.tftnews.com All Rights Reserved