首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-05-28 13:30:50
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-05-28
手機掃碼考試答題軟件
手機掃碼考試答題軟件
目前全球疫情蔓延,經濟形勢不容樂觀,很多行業都内卷嚴重,故此不少畢業生都會選擇繼續學習考研或者考公,而中小學或成人教育等一般都需要用到學習考試的app,故此考試類APP目前在市面上需求也越來越多,一般一款比較好的功能齊全的考試小程序或者ap...
2026-05-28
合作醫療手機怎樣繳費
合作醫療手機怎樣繳費
合作醫療手機怎樣繳費?首先要關注當地繳納居民醫療保險的公衆号,這個一般社保中心會提前公布在網絡上,關注就可以了,接下來我們就來聊聊關于合作醫療手機怎樣繳費?以下内容大家不妨參考一二希望能幫到您!合作醫療手機怎樣繳費首先要關注當地繳納居民醫療...
2026-05-28
絕地求生更新哪個服務器好
絕地求生更新哪個服務器好
絕地求生這款大熱的遊戲其實就是自由度高,每局遊戲都能體驗到不一樣的樂趣,隻有活到最後的玩家才是勝者!而很多玩家熟知的技巧就是防守靠苟進攻靠陰,即便是每局遊戲都很認真打,想要吃雞也是困難重重。此外不同的服務器難度也不太一樣,今天小編就帶大家一...
2026-05-28
中建科技去年盈利水平
中建科技去年盈利水平
哈喽大家好呀我是你們朝思暮想的土木好學長,之前我們介紹了很多工程局,這些工程局大部分都是一些早已成立的工程局,今天學長跟大家介紹一家剛成立不久的新公司,雖然是新公司但是公司主要做的項目在未來卻很有前景,沒錯就是中建科技。如果你想了解更多工程...
2026-05-28
Copyright 2023-2026 - www.tftnews.com All Rights Reserved