首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2025-10-28 08:26:59
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
推荐阅读
電腦玩吃雞太卡怎麼辦windows7
電腦玩吃雞太卡怎麼辦windows7
電腦玩吃雞太卡怎麼辦windows7?這裡英特爾顯卡為例子,鼠标右擊桌面空白處彈出菜單選中圖形屬性,我來為大家科普一下關于電腦玩吃雞太卡怎麼辦windows7?下面希望有你要的答案,我們一起來看看吧!電腦玩吃雞太卡怎麼辦windows7這裡...
2025-10-28
長安鈴木骁途這車怎麼樣
長安鈴木骁途這車怎麼樣
長安鈴木一直以小型車為主,旗下布局有鋒馭、維塔拉和雨燕等車型。今年長安鈴木還将推出全新小型SUV骁途。網上車市從國家工信部獲悉,骁途将搭載一台最大功率為90kW的1.6L發動機,匹配手動和CVT變速箱,部分車型配有智能全時四驅系統。新車将于...
2025-10-28
電腦長期不關機有什麼影響
電腦長期不關機有什麼影響
電腦長期不關機有什麼影響?長時間不關電腦這樣對電腦損害不是很大,但是還是有一些損耗的,電腦硬件的壽命和保養一定不是由電腦是否開關機來決定的,一般決定電腦壽命的是你日常使用電腦的次數還有你使用的時間,還有你用來電腦的用途,這些才是會對電腦造成...
2025-10-28
換工作時異地公積金怎麼弄
換工作時異地公積金怎麼弄
換工作時異地公積金怎麼弄?“換工作到了貴陽,可是原來所在城市的工作單位公積金賬戶裡還有錢,該怎麼辦?”近來,不少市民向貴陽市融媒問政平台咨詢有關公積金異地轉移接續的問題,今天小編就來說說關于換工作時異地公積金怎麼弄?下面更多詳細答案一起來看...
2025-10-28
停車場管理系統項目概述與設計
停車場管理系統項目概述與設計
停車場管理系統相對來說比較簡單,施工的話基本上千篇一律,隻要你從頭參與一次停車場管理系統的施工,那麼以後各種場景,你都會了,停車場管理系統如何施工呢?今天分享一套海康家的停車場管理系統施工方案。一、施工規範及工藝1.1管的分類線管有PVC材...
2025-10-28
Copyright 2023-2025 - www.tftnews.com All Rights Reserved