首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-08-27 12:20:28
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-08-27
機器學習數據标簽特征
機器學習數據标簽特征
GoogleRephil是GoogleAdSense背後廣告相關性計算的頭号秘密武器。但是這個系統沒有發表過論文。隻是其作者(博士UriLerner和工程師MikeYar)在2002年在灣區舉辦的幾次小規模交流中簡要介紹過。所以KevinM...
2026-08-27
生活中哪些是納米技術
生活中哪些是納米技術
生活中哪些是納米技術?衣:在紡織和化纖制品中添加納米微粒,可以除味殺菌化纖布雖然結實,但有煩人的靜電現象,加入少量金屬納米微粒就可消除靜電現象,今天小編就來聊一聊關于生活中哪些是納米技術?接下來我們就一起去研究一下吧!生活中哪些是納米技術衣...
2026-08-27
win10專業版系統有多大
win10專業版系統有多大
最近看到很多自媒體在推一個精簡版的WIN10系統,說是内存占用僅1GB,C盤空間僅需要4.29G,系統鏡像文件僅2.51G,系統是基于Windows1021H2LTSC精簡而來的,事實上LTSC本身就是微軟官方的精簡系統,再精簡下去還能用嗎...
2026-08-27
美潔佳水管清洗機測評怎麼樣
美潔佳水管清洗機測評怎麼樣
家中的管道清潔是一件非常麻煩的事情,找工人來清潔不僅需要自己抽出時間不說還需要預約工人搭配上工人的時間,并且也要耗費不少的資金,所有事情都想嘗試自己幹的我為了可以自己清潔管道而入手了美潔佳水管清洗機,清潔水管有它之後就變得方便多啦。這款管道...
2026-08-27
Copyright 2023-2026 - www.tftnews.com All Rights Reserved