首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-06-21 21:51:00
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
推荐阅读
如何在沒有搜索引擎的網站搜索
如何在沒有搜索引擎的網站搜索
1、在沒有搜索引擎的網站搜索:ctrl+f搜索查找關鍵詞。2、自己設計表單、編程、與數據庫鍊接檢索。...
2026-06-21
電腦上怎麼做表格
電腦上怎麼做表格
1、用Word制作表格,開一個空白的文檔,在菜單欄中選擇“表格”,執行“插入”-“表格”命令;在打開...
2026-06-21
自制挖掘機怎麼做?
自制挖掘機怎麼做?
1、利用瓦楞紙闆先制作挖掘機的駕駛艙,以及車上其他零部件。2、将駕駛艙用熱熔膠粘在底闆上,并且用膠水...
2026-06-21
蘋果手機通用裡沒有設備管理怎麼辦
蘋果手機通用裡沒有設備管理怎麼辦
演示機型:Iphone12系統版本:iOS14.41、打開手機,點擊設置。2、頁面下拉之後,點擊通用的選項進入。3、進入之後頁面下拉,有一個描述文件與設備管理功能,需要點擊。4、把企業級應用的第一個應用打開。5、打開後便會跳出界面,點擊信任确定即可。蘋果手機使用小技巧:1、計算器妙用:iPhone手機裡的計算機,平時都是用來進行一些簡單的加減乘除。隻要将計算機橫向過來,就能開啟科學計算器,一些方程
2026-06-21
gt2運動版時尚版有什麼區别
gt2運動版時尚版有什麼區别
1、華為智能手表WATCHGT2運動版和時尚版功能和配置一樣,在功能上都具有心率監測、智能提醒、睡眠監測、社交娛樂、計步、防水等功能,沒有區别。2、在外觀上有所不同,表盤和表帶有所區别,還有顔色外觀有所差異。時尚款的是真皮的,運動款的是矽膠的。總體還是比較智能的,這兩款都不錯,搭配上爬山運動裝,不怕擔心電話信息看不到漏接漏看,他有很多提醒功能,是運動愛好者的選擇之一。
2026-06-21
Copyright 2023-2026 - www.tftnews.com All Rights Reserved