首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-01-30 10:33:09
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
推荐阅读
m8 adigo 版本
m8 adigo 版本
比美高給我們帶來了驚喜,是驚多一點還是喜多一點呢……2014年,法拉利發布了基于LaFerrari打造的FXXK,其中“K”代表KERS,即動能回收系統。FXXK是LaFerrari的落場版,但不能參加國際汽聯的比賽,更不可以上路,不符合任...
2026-01-30
最好的三種安卓手機
最好的三種安卓手機
十年前的這時,你在做什麼?相信很多讀者朋友還在大學校園,或者剛剛畢業準備參加工作,十年足以改變很多事情。時間回到十年前,2010年“銀河”中出現了一顆星,即是今天的主角,我們耳熟能詳的GalaxyS系列。和蘋果iPhone對飙十年,Gala...
2026-01-30
win10電腦怎樣強制進入安全模式
win10電腦怎樣強制進入安全模式
操作系統是使用計算機的基本程序,windows操作系統占據了PC市場的90%。現在用戶最多的是Win10操作系統,如果在win10系統中遇到問題,可以進入安全模式進行修複。安全模式是微軟操作系統下的一種特殊模式。一般情況下,啟動時可以按F8...
2026-01-30
twitter全球移動報告
twitter全球移動報告
據外媒MSPoweruser消息,Twitter的GooglePlay商店安裝量已突破10億。目前,大約有25個應用在Android上的安裝量已突破10億大關,幾乎所有應用都由谷歌、微軟、Facebook或三星擁有。Twitter安裝量已突...
2026-01-30
ios14.7快捷功能介紹
ios14.7快捷功能介紹
對于很多愛折騰的小夥伴來說,很喜歡體驗最新的測試版系統,希望提前用上iOS系統的最新功能。今天跟大家分享一個查詢iOSBeta開放系統的捷徑指令。這是一款,可以查詢蘋果所有開放系統的捷徑指令,如果想查詢目前有哪些版本可以刷機的話,就可以借助...
2026-01-30
Copyright 2023-2026 - www.tftnews.com All Rights Reserved