首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-03-13 18:45:03
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
推荐阅读
電腦白屏了怎麼辦
電腦白屏了怎麼辦
電腦白屏了怎麼辦?顯卡生鏽導緻接觸不良電腦顯卡的金屬片可能常年使用發生氧化生鏽,導緻金屬部位信息傳輸異常,可以先關閉電腦電源,将顯卡取出來,然後擦拭掉上面的鏽迹或者灰塵污漬,之後重新安裝就可以恢複正常了,接下來我們就來聊聊關于電腦白屏了怎麼...
2026-03-13
vivo s15 pro所有參數
vivo s15 pro所有參數
VIVOS15PRO配置參數詳情規格參數商品編号100035668733主體機型vivoS15Pro入網型号V2207A上市日期2022-05-27基本信息機身尺寸寬7352mm長1589mm厚8.55mm機身重量188g機身顔色盛夏CPU...
2026-03-13
windows原版系統安裝方法
windows原版系統安裝方法
原本win10怎麼一鍵安裝,系統鏡像一般分為原版系統與Ghost版本的系統,Ghost系統就是用戶在原版系統基礎上進行diy然後用Ghost技術封裝的操作系統,Ghost版本系統很多人對它的印象都是有病毒、一大堆流氓軟件,可一鍵安裝,雖然安...
2026-03-13
手機是買蘋果的還是華為
手機是買蘋果的還是華為
手機是買蘋果的還是華為?這是9月份數碼圈最熱門的話題先說下個人的答案,今天華為開售,線下店定了台Mate50pro,搭售碎屏險,沒有昆侖版本,我來為大家講解一下關于手機是買蘋果的還是華為?跟着小編一起來看一看吧!手機是買蘋果的還是華為這是9...
2026-03-13
三維碼有什麼商機嗎
三維碼有什麼商機嗎
三維碼有什麼商機嗎?三維碼可在保密,防僞,公共安全等重要領域中應用,今天小編就來說說關于三維碼有什麼商機嗎?下面更多詳細答案一起來看看吧!三維碼有什麼商機嗎三維碼可在保密,防僞,公共安全等重要領域中應用。三維碼具有更大的信息容量、相同的識别...
2026-03-13
Copyright 2023-2026 - www.tftnews.com All Rights Reserved