首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2025-12-24 23:29:05
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
推荐阅读
無線網卡如何安裝使用
無線網卡如何安裝使用
無線網卡如何安裝使用?首先,将無線網卡與電腦相連對于USB無線網卡,隻需要插入電腦USB接口即可而對于PCI插槽式無線網卡,則需要打開機箱,将其插入電腦PCE插槽内才行,現在小編就來說說關于無線網卡如何安裝使用?下面内容希望能幫助到你,我們...
2025-12-24
傳動系統警告燈亮原因
傳動系統警告燈亮原因
傳動系統警告燈亮原因?變速箱可能有問題,如果你的車沒有過保建議你趕緊去4s店檢查,把該換的換了,我來為大家科普一下關于傳動系統警告燈亮原因?以下内容希望對你有幫助!傳動系統警告燈亮原因變速箱可能有問題,如果你的車沒有過保建議你趕緊去4s店檢...
2025-12-24
夢到手機碎了
夢到手機碎了
夢到手機碎了?夢見和老公吵架摔手機,預示着最近的好運一般是來自陌生人,也會有機會結交新朋友,也會因此增長見識,我來為大家講解一下關于夢到手機碎了?跟着小編一起來看一看吧!夢到手機碎了夢見和老公吵架摔手機,預示着最近的好運一般是來自陌生人,也...
2025-12-24
vivo
vivo
vivo?vivoX9可以設置不聯網,打開手機自帶應用【i管家】,進入i管家以後點擊【流量監控】圖标,接下來我們就來聊聊關于vivo?以下内容大家不妨參考一二希望能幫到您!vivovivoX9可以設置不聯網,打開手機自帶應用【i管家】,進入...
2025-12-24
我的電腦qq空間打不開怎麼辦
我的電腦qq空間打不開怎麼辦
我的電腦qq空間打不開怎麼辦?點擊浏覽器上的工具選擇internet選項打開的internet屬性點擊删除浏覽曆史記錄,我來為大家科普一下關于我的電腦qq空間打不開怎麼辦?下面希望有你要的答案,我們一起來看看吧!我的電腦qq空間打不開怎麼辦...
2025-12-24
Copyright 2023-2025 - www.tftnews.com All Rights Reserved