首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-04-23 20:46: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
推荐阅读
零基礎英語啟蒙動畫
零基礎英語啟蒙動畫
看過《kidsABC》的朋友都知道,它是有真人參與,圍繞日常用語展示故事、兒歌,以及以動畫展示出來的字母學習内容。一套學習Phonics自然拼讀法的啟蒙動畫教程,是真人動畫的展示形式。這樣的一種形式展示的兒歌和以動畫展示的自然拼讀啟蒙内容,...
2026-04-23
如何安裝攝像頭
如何安裝攝像頭
如何安裝攝像頭?将線材連接到攝像頭的時候需要使用BNC接頭,用冷壓鉗将線材和BNC頭連接壓緊,我來為大家科普一下關于如何安裝攝像頭?以下内容希望對你有幫助!如何安裝攝像頭将線材連接到攝像頭的時候需要使用BNC接頭,用冷壓鉗将線材和BNC頭連...
2026-04-23
上的滾動字幕怎麼做
上的滾動字幕怎麼做
如何制作視頻片後滾動字幕?小夥伴們在電影、電視播放結束,會在片尾出現演職人員的名字,這是怎麼做到的呢?下面,小編就為大家介紹下制作視頻片後滾動字幕方法。打開premiere軟件,把視頻導入素材庫,同時新建序列,把視頻拖進操作區,點擊菜單欄的...
2026-04-23
微信視頻号從哪裡開啟
微信視頻号從哪裡開啟
微信視頻号從哪裡開啟?在發現裡開啟視頻号步驟:首先在手機中打開微信,點擊菜單欄中的“發現”,點擊上方的“視頻号”,下面我們就來聊聊關于微信視頻号從哪裡開啟?接下來我們就一起去了解一下吧!微信視頻号從哪裡開啟在發現裡開啟視頻号。步驟:首先在手...
2026-04-23
qq8.4.8支持安卓系統
qq8.4.8支持安卓系統
騰訊QQ團隊近日發布了安卓手機QQ8.3.9内測版,按照前幾個月的慣例,這可能是此測試版的第一輪測試,添加的功能隻有一個大項,即資料卡架構重構。有可能還有後續的測試版,不排除會新增一些其它的功能。主要更新内容全方位重構優化資料卡的架構,涉及...
2026-04-23
Copyright 2023-2026 - www.tftnews.com All Rights Reserved