首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2024-10-04 06:28:33
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
推荐阅读
android go系統的手機
android go系統的手機
最近,谷歌小型或廉價智能手機操作系統正式發布,此次發布的Android12Go系統,适合更低廉或小型智能手機配置。對于手機内存不是很大的用戶來說,真是個好消息。全新的Android12Go版系統,更安全、更流暢、更省電。不少網友認為,該款操...
2024-10-04
物聯網應用技術的就業方向
物聯網應用技術的就業方向
物聯網應用技術的就業方向?目前非純軟件産品的IT公司基本都會有物聯網人才的需求,這樣的企業包括手機、通信、醫療、家用電器、安防等衆多行業,例如三星、西門子、飛利浦、通用電器、思科、華為、大唐電信等IT知名企業目前正在招聘物聯網工程師,接下來...
2024-10-04
yc聯合創始人融資建議
yc聯合創始人融資建議
此次A輪融資具有裡程碑意義,本輪融資後公司除了繼續門店規模化擴張外,将進一步深化自主開發的訂貨系統打通設計師與門店的數據對接,并升級2018年3月開業的全新項目-設計師聯合零售市集WeMarket。AnyShopStyle是國内首家數據驅動...
2024-10-04
oppor15目前性能怎麼樣
oppor15目前性能怎麼樣
OPPOR15的價格終于公布了,這次OPPO非常聰明,選擇了一種比較有吸引力的配置方案,我們今天就來好好分析一下。另外一個差異比較大的地方就是攝像頭了。标準版的後攝像頭采用的是1600萬500萬像素的雙攝方案,顯然是有縮水,這應該也是銷售層...
2024-10-04
一塊好的面料會帶來無限的靈感哦
一塊好的面料會帶來無限的靈感哦
本刊記者-雷蕾章簡長發商業·2019中國面料之星系列活動是由中國紡織工業聯合會指導、《紡織服裝周刊》雜志社主辦,長發商業中心獨家冠名、CFU創意時尚聯盟協辦、德州華源生态科技有限公司支持的最具影響力的面料調查活動。本期報道,我們将向大家介紹...
2024-10-04
Copyright 2023-2024 - www.tftnews.com All Rights Reserved