首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2025-12-23 07:16:21
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
推荐阅读
杭州電子科技大學的生源
杭州電子科技大學的生源
“四電四郵”之杭州電子科技大學都知道兩電一郵,指的是電子科技大學、西安電子科技大學,北京郵電大學,因為他們是985、211高,其實還有幾所雙非院校,也屬于電子信息熱門專業特色院校,他們是:桂林電子科技大學、杭州電子科技大學、南京郵電大學、西...
2025-12-23
surface
surface
surface?首先,從硬件參數來看,微軟已經為其高端SurfacePro6配備了英特爾酷睿i7-8650U處理器作為第八代的酷睿處理器在性能方面相當于上一代的産品有着十分大的提升,此外微軟還為Pro6提供Corei5-8250U或Core...
2025-12-23
電腦打印時間錯誤怎麼辦
電腦打印時間錯誤怎麼辦
今天被華為電腦驚到了,怎麼有這麼有違常識的問題呢???實在是沒想到,華為竟然也會出現這樣不符合常理的問題!我的安全感再一次被撼動了。事情是這樣的:因為疫情原因,孩子在家上網課,老師發了練習題,讓自己打印出來做。我都要被折騰吐血了也打印不出來...
2025-12-23
戴爾新靈越開機激活
戴爾新靈越開機激活
新的戴爾靈越系列筆記本有個翻蓋就自動開機的功能,如果平時不需要這個功能,可以在BIOS裡面關閉。打開BIOS,找到PowerManagement,然後在這個選項裡面找到這個選項:PowerOnLidOpen,關系這個選項就可以了。,
2025-12-23
自己手機上的二維碼怎麼掃描
自己手機上的二維碼怎麼掃描
自己手機上的二維碼怎麼掃描?首先我們需要把别人發的二維碼保存到手機上,然後可以使用qq、微信、支付寶還有浏覽器,現在小編就來說說關于自己手機上的二維碼怎麼掃描?下面内容希望能幫助到你,我們來一起看看吧!自己手機上的二維碼怎麼掃描首先我們需要...
2025-12-23
Copyright 2023-2025 - www.tftnews.com All Rights Reserved