首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-07-07 04:30:06
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
推荐阅读
win11安卓子系統最新版本使用體驗
win11安卓子系統最新版本使用體驗
前不久,Win11推出了首個重大版本更新,其中發布了一項重要内容,Win11正式推出Android子系統,支持上千款安卓應用在Windows11上運行。其實我本身對于Windows系統日常版本的更新是不敏感的。不過這次對于支持安卓APP的安...
2026-07-07
隻能在5g時代賣4g智能手機
隻能在5g時代賣4g智能手機
圖片來源@視覺中國钛媒體注:本文來源于微信公衆号新浪科技(ID:techsina),作者|張俊,編輯|韓大鵬,钛媒體經授權發布。劃重點:1、今年1月,國内5G手機出貨量同比罕見下滑,創四個月最低。相反,4G手機的出貨量創下近一年來的次高點。...
2026-07-07
家長如何預防孩子上網
家長如何預防孩子上網
當孩子出現以下情形,家長就應該多多注意喔!1.他們每天在同一時間使用電腦許多家長不理解孩子和青少年為什麼這麼容易成為網絡獵捕者的目标?也不明白這個過程其實不是一夜之間發生的。一些獵捕者假扮成與狩獵目标同齡的孩子,獵捕者會故意做些增加孩子信任...
2026-07-07
快剪輯怎麼自動生成字幕
快剪輯怎麼自動生成字幕
快剪輯怎麼自動生成字幕?手機桌面上打開快剪輯APP軟件首頁,點擊“剪輯”導入視頻,接下來我們就來聊聊關于快剪輯怎麼自動生成字幕?以下内容大家不妨參考一二希望能幫到您!快剪輯怎麼自動生成字幕手機桌面上打開快剪輯APP。軟件首頁,點擊“剪輯”導...
2026-07-07
蘋果鬧鐘音量怎麼調
蘋果鬧鐘音量怎麼調
蘋果鬧鐘音量怎麼調?蘋果鬧鐘音量調聲音直接打開手機待機頁面的設置選項進入設置頁面之後滑動手機屏幕點擊聲音與觸感,将按鈕調整選項打開,然後拖動小圓點即可調節鬧鐘聲音大小了,今天小編就來說說關于蘋果鬧鐘音量怎麼調?下面更多詳細答案一起來看看吧!...
2026-07-07
Copyright 2023-2026 - www.tftnews.com All Rights Reserved