首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-07-02 04:19:15
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
推荐阅读
怎樣鑒别真假iPhone手機
怎樣鑒别真假iPhone手機
1、打開設置”,點擊通用”,點擊關于本機”,下拉頁面即可找到手機序列号。2、打開蘋果官網,點擊技術支持”,在下拉頁面中點擊查看您産品的保修狀态”。3、輸入手機的序列号和驗證碼,點擊繼續”即可看到手機的保修狀态。4、如果沒有相關信息則手機不是真機。
2026-07-02
雙模sa/nsa什麼意思
雙模sa/nsa什麼意思
SA和NSA分别表示5G獨立組網和非獨立組網。在5GNSA組網方式下,運營商可以4G、5G共用核心網,節省網絡投資,但缺點是無法支持低延時等5G新特性。而且手機在NSA網絡下需要同時連接4G和5G網絡,耗電也比SA網絡下高。為節省開支,部分運營商會在5G建網初期采用NSA方式,但SA才是是5G的最終...
2026-07-02
deepin忘記開機密碼怎麼辦
deepin忘記開機密碼怎麼辦
1、開機進入系統選擇界面,選擇要進入的系統的那一項上,然後按下鍵盤上的e”鍵。2、然後進入了下面的界面。3、在出現的畫面當中,按幾下鍵盤的下方向鍵,把光标移動到linux/boot/....”的一行,找到其中的rosplashquiet”将其删除後替換為:rwsingleinit=/bin/bash...
2026-07-02
全民k歌本地錄音怎麼保存到手機上
全民k歌本地錄音怎麼保存到手機上
演示機型:iPhone12&&華為P40&&小米11系統版本:iOS14&&EMUI11&&miui12.0.7APP版本:全民k歌7.19.681、在手機上打開全民K歌,點擊登錄按鈕。2、登錄進入到全民K歌界面以後點擊下面的點歌按鈕進入。3、頁面跳轉以後點擊需要查看的歌曲進入,點擊右上角的三個圓點。4、此時可以在手機底部看到彈出的選項,點擊下載按鈕。5、點擊下載以後可以在屏幕中看到該歌曲正在進行
2026-07-02
淘寶付定立減是什麼意思
淘寶付定立減是什麼意思
指的是消費者購買參加活動的預售商品時,可享受在預售商品總價上的立減優惠,立減金額為定金的0.5、1、1.5或2倍四個倍數。舉例:預售商品2000元,定金100元,商家支持付定立減定金的2倍。消費者下單後預售價減去200變為1800,尾款需付1700。定金:定金是指當事人雙方為了保證債務的履行,約定由...
2026-07-02
Copyright 2023-2026 - www.tftnews.com All Rights Reserved