首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-05-09 18:15:16
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
推荐阅读
mac怎樣切換windows系統
mac怎樣切換windows系統
很多用戶都會在使用Mac電腦時安裝win系統,這樣使用雙系統讓工作更有效率,但一些新安裝win系統的Mac用戶不知道如何切換系統,下面我們分享在Mac電腦中切換系統的操作方法。1、将Mac開機或重啟後,2、然後立即按住鍵盤上的“Option...
2026-05-09
中歐班列來蘭州新區
中歐班列來蘭州新區
中歐班列來蘭州新區?來源:【甘肅廣電-視聽甘肅】,我來為大家科普一下關于中歐班列來蘭州新區?下面希望有你要的答案,我們一起來看看吧!中歐班列來蘭州新區來源:【甘肅廣電-視聽甘肅】1月14日,一列滿載着50個40英尺集裝箱,貨重1300餘噸,...
2026-05-09
海美迪播放器索尼
海美迪播放器索尼
海美迪産品解碼強畫質好,從網絡機頂盒到高清播放機,在市場上都是有口皆碑的。而本次的小編拿到手的是4K播放機H1000,不同于以往的圓潤小巧,在外觀上做出了重大的突破,機身四平八穩,邊角的處理采用銳利硬朗的風格,裸機重量達到6.25公斤,體積...
2026-05-09
微軟surface全系列
微軟surface全系列
微軟surface全系列?10月12日周三,微軟推出了SurfaceLaptop5、SurfacePro9平闆電腦和SurfaceStudio2一體機,今天小編就來說說關于微軟surface全系列?下面更多詳細答案一起來看看吧!微軟surf...
2026-05-09
bilibili頭像框怎麼獲得
bilibili頭像框怎麼獲得
近日,動畫「pop子和pipi美的日常」官方公開了本作第二季的最新視覺圖,改編自漫畫家大川ぶくぶ創作的喜劇四格漫畫作品,TV動畫《pop子和pipi美的日常》(POPTEAMEPIC)第2季确定将于2022年10月1日01:00在bilib...
2026-05-09
Copyright 2023-2026 - www.tftnews.com All Rights Reserved