首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-01-20 19:05:14
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
推荐阅读
酷睿和英特爾處理器有什麼區别
酷睿和英特爾處理器有什麼區别
将Intel至強與IntelCoreCPU進行比較時,Intel至強CPU為數據密集型企業和工業應用提供了更多的集體價值。但是,考慮到成本和應用的軟件類型,有一些因素表明英特爾酷睿CPU可能更适合特定的企業和工業應用。下面我們對英特爾至強和...
2026-01-20
三星Galaxy S23 發布時間
三星Galaxy S23 發布時間
IT之家7月20日消息,本月初,三星表示沒有重新推出GalaxyNote系列手機的計劃,并且會通過每年推出的新款GalaxySUltra機型來保持Note精神延續。今日,數碼博主@UniverseIce爆料了三星GalaxyS23Ultra...
2026-01-20
泰康保險平台是真實的嗎
泰康保險平台是真實的嗎
泰康保險平台是真實的嗎?東北網3月15日訊2017年,順應互聯網科技發展大趨勢,泰康人壽加大了人工智能應用,在業内率先引入人臉識别、OCR(光學字符識别)自動識别、智能機器人等技術新技術應用在微信平台的回執簽收、智能客服和保單貸款等環節,不...
2026-01-20
手機怎麼取消鎖屏
手機怎麼取消鎖屏
随着萬物互聯的大趨勢,智能手機在我們日常生活中的作用也越來越大,這其中就包括個人隐私以及銀行賬戶等信息。所以,如今的智能手機都會有屏幕鎖,而且大部分手機更是加入了指紋解鎖功能。那麼問題來了,對于最普通的手機基礎用戶,手機鎖屏就會顯得有些累贅...
2026-01-20
qx50買車送保養嗎
qx50買車送保養嗎
qx50買車送保養嗎?3月試駕P5免費領取“騰訊視頻VIP季卡”一張,接下來我們就來聊聊關于qx50買車送保養嗎?以下内容大家不妨參考一二希望能幫到您!qx50買車送保養嗎3月試駕P5免費領取“騰訊視頻VIP季卡”一張歡迎緻電咨詢:027-...
2026-01-20
Copyright 2023-2026 - www.tftnews.com All Rights Reserved