首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-07-22 04:30:17
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-07-22
吉他夾變調的使用方法
吉他夾變調的使用方法
變調夾是吉他彈唱中常用的輔助工具,它對于學會了常用幾個和弦指法的初學者來說,變調夾是彈唱的好幫手。我們可以通過使用變調夾,就可以彈唱任意曲調的歌曲啦。因為初學者一般隻熟練C調的幾個常用和弦,但是有些歌曲彈唱出來效果可能不理想,覺得唱和彈不在...
2026-07-22
手機信号欄出現g是什麼情況
手機信号欄出現g是什麼情況
用過很多手機,從摩托到蘋果三星,從諾基到中興華為,從塞班到安卓,從WP到iOS,從移動到聯通電信,從2G到3G4G……手機在變,号碼在變,運營商在變,手機信号欄的标識也一直在變。今天就跟大家聊一聊手機信号欄這些标識,不知道到的可以了解一下漲...
2026-07-22
做好的系統u盤怎麼重裝系統
做好的系統u盤怎麼重裝系統
上期我們講到如何制作純淨版的系統U盤本期就給大家講一下如何使用系統U盤給電腦重裝系統或者修複系統!一,準備工作電腦在關機情況下插入系統U盤!二,開機操作然後按下電源鍵,狂按F8(主闆有所差異,BIOS鍵也有所差異)以下為對照表進入BIOS後...
2026-07-22
無人智慧門店系統
無人智慧門店系統
這幾年移動互聯網飛速發展,同時也衍生出了許多的高科技産物,數字門店系統就是其中之一。傳統的一些營銷模式已經漸漸地淡出了大衆視野,随着數字經濟時代的到來,衆多商家跟門店也不得不通過數字門店系統轉型,從而避免自己被智慧時代淘汰。什麼是數字化營銷...
2026-07-22
Copyright 2023-2026 - www.tftnews.com All Rights Reserved