首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2025-12-19 11:29:12
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、安裝時,布氏漏鬥頸的斜口要遠離且面向吸濾瓶的抽氣嘴。抽濾時速度(用流水控制)要慢且均勻,濾液不能超過抽氣嘴。2、抽濾過程中,若漏鬥内沉澱物有裂紋時,要用玻璃棒及時壓緊消除,以保證吸濾瓶的低壓,便于吸濾。
2025-12-19
dxf文件怎麼打開
dxf文件怎麼打開
1、在浏覽器搜索下載相關CAD編輯器工具。2、安裝并運行CAD編輯工具,從其程序主界面中點擊“打開”...
2025-12-19
嬰兒車怎麼折疊
嬰兒車怎麼折疊
1、首先,你要在嬰兒推車的推把上面找到折疊按鈕,然後按其正确的方向去推移,這種操作可以使得嬰兒推車處...
2025-12-19
net40是什麼
net40是什麼
全稱netframework4.0。是Microsoft.NETFramework的4.0版本,是用于Windows的新托管代碼編程模型。NETFramework安全解決方案基于管理代碼的概念,以及由通用語言運行時(CLR)加強的安全規則。大部分管理代碼需要進行驗證以确保類型安全及預先定義好的其它屬性的行為的安全。安全策略包含了許多代碼組,這些組包含了根據證據應給予的許可權。代碼組描述的許可可提供
2025-12-19
duv和euv技術區别
duv和euv技術區别
DUV是深紫外線(DeepUltravioletLithography),EUV是極深紫外線(ExtremeUltravioletLithography)。從制程範圍來看,DUV基本上隻能做到25nm,Intel憑借雙工作台的模式做到了10nm,但是卻無法達到10nm以下。隻有EUV能滿足10nm以下的晶圓制造,并且還可以向5nm、3nm繼續延伸。
2025-12-19
Copyright 2023-2025 - www.tftnews.com All Rights Reserved