首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-05-14 04:15:31
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
推荐阅读
東方紅ME604拖拉機參數
東方紅ME604拖拉機參數
1、品牌:東方紅型号:ME604/ME604-12、分類:輪式拖拉機3、配套功率:60馬力4、驅動形...
2026-05-14
抖音歌詞跳動是怎麼做的
抖音歌詞跳動是怎麼做的
以iphone12,ios14,抖音v14.9.0,美冊5.5.7為例。1、打開美冊短視頻專區,點擊“3D環繞音效”功能按鈕,導入準備好的音樂素材,軟件内也有提供音樂,點擊屏幕上的文字,可以編輯它們的内容。2、點擊底部“主題”按鈕,選擇一個合适的特效,點擊底部“背景”按鈕,軟件内提供大量圖片和視頻的背景,也可使用手機裡的背景素材。3、特效和背景編輯好後,點擊字幕按鈕,軟件會智能提取出音頻中的文字,
2026-05-14
手機暢連功能是什麼意思
手機暢連功能是什麼意思
以華為P40、EMUI11為例。暢連通話是EMUI10系統推出的高清通話功能,可以突破多設備互通壁壘,讓你體驗全場景便捷通話。撥号即可與其他華為設備進行最高1080P高清視頻通話。華為技術有限公司(HUAWEITECHNOLOGIESCO.,LTD.)是一家生産銷售通信設備的民營通信科技公司,成立于1987年,總部位于中國廣東省深圳市龍崗區。華為作為全球領先的信息與通信技術(ICT)解決方案供應商
2026-05-14
什麼是mb
什麼是mb
1、MB有很多意思,最常見的是用來表示流量,全稱是MBbyte,中文意思為兆,是計算機中的一個數據的...
2026-05-14
電腦超頻什麼意思
電腦超頻什麼意思
1、指讓電腦的配件在高于标準頻率下工作的一行為。在通常的情況下,我們所說的電腦超頻主要是指電腦CPU...
2026-05-14
Copyright 2023-2026 - www.tftnews.com All Rights Reserved