首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-04-14 17:06:35
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
推荐阅读
linux 讀不到i2c設備
linux 讀不到i2c設備
①I2C知識點1.I2C協議:時鐘線、數據線①空閑狀态:i2c總線的SCL和SDA信号線同時為高。②開始信号:SCL為高,SDA由高到低。停止信号:SCL為高,SDA由低到高。③應答信号:發送器每發送一個字節(8bit),就在時鐘脈沖9期間...
2026-04-14
華碩飛行堡壘fx53vd遊戲本
華碩飛行堡壘fx53vd遊戲本
當今的筆記本電腦正在根據用途分化出不同的趨勢,上網本趨于日常辦公以及電影,商務本趨于穩定低功耗獲得更長久的續航時間,家用本擁有不錯的性能和很高的性價比,遊戲本則是專門為了迎合少數人群外出遊戲使用的。算是個大屏手機筆記本電腦能玩大型網絡遊戲麼...
2026-04-14
顯卡公版什麼意思
顯卡公版什麼意思
顯卡公版什麼意思?公版就是硬件廠商按照原廠GPU參數制造出的顯卡,包括外觀,PCB做工、頻率等都和GPU廠商官方的一樣,接下來我們就來聊聊關于顯卡公版什麼意思?以下内容大家不妨參考一二希望能幫到您!顯卡公版什麼意思公版就是硬件廠商按照原廠G...
2026-04-14
手機來電話不顯示接聽界面
手機來電話不顯示接聽界面
手機來電話不顯示接聽界面?手機來電話不顯示接聽界面,這是手機未開啟來電鎖屏通知功能的緣故,開啟方法如下:,現在小編就來說說關于手機來電話不顯示接聽界面?下面内容希望能幫助到你,我們來一起看看吧!手機來電話不顯示接聽界面手機來電話不顯示接聽界...
2026-04-14
電腦突然就黑屏怎麼回事
電腦突然就黑屏怎麼回事
電腦突然就黑屏怎麼回事?按鍵盤喚不醒,不算是硬件問題,很多時候隻是硬件驅動問題,大多數時候更新驅動程序就可以恢複正常,下面我們就來聊聊關于電腦突然就黑屏怎麼回事?接下來我們就一起去了解一下吧!電腦突然就黑屏怎麼回事按鍵盤喚不醒,不算是硬件問...
2026-04-14
Copyright 2023-2026 - www.tftnews.com All Rights Reserved