首页
/
每日頭條
/
科技
/
c語言正則表達式怎麼寫
c語言正則表達式怎麼寫
更新时间:2026-05-14 17:03: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
推荐阅读
為什麼很多食品都添加苯甲酸鈉
為什麼很多食品都添加苯甲酸鈉
哈喽,大家好,我是相信自己餐飲管理,傳播美食技術的姚師傅,今天給大家說說科技與狠活裡的防腐添加劑:苯甲酸鈉。首先說一下,一些天然的食物中就含有苯甲酸鈉。比如:藍莓、蘋果、李子、小紅莓、蔓越莓、梅幹、肉桂和丁香中都含有苯甲酸鈉。苯甲酸鈉還有一...
2026-05-14
資生堂盼麗眼霜的用法
資生堂盼麗眼霜的用法
資生堂盼麗眼霜的用法?,現在小編就來說說關于資生堂盼麗眼霜的用法?下面内容希望能幫助到你,我們來一起看看吧!資生堂盼麗眼霜的用法
2026-05-14
手機聽筒最大聲音越來越小咋處理
手機聽筒最大聲音越來越小咋處理
在這個“無手機不生活”的時代裡,有一天你打着電話,突然聲音變小,任憑像拿着對講機一樣呐喊……很多人在使用手機的時候經常會遇到這樣的問題,手機聽筒聲音越來越小,遠不如剛買來用的時候聲音大,甚至在稍微嘈雜的環境中根本聽不清對方說話的聲音了,這是...
2026-05-14
nfc為什麼有的門禁卡不能複制
nfc為什麼有的門禁卡不能複制
關于手機的NFC功能,究竟有哪些作用,是否雞肋,一直為廣大網友所争論,其實問題的重點還是在于人,你處于什麼城市,一線城市還是四五線城市,這個決定了手機的NFC使用範圍和廣度。NFC功能最常用的地方有兩個:複制門禁卡、乘坐公交車。今天小迷蟲一...
2026-05-14
m3u8文件能合成一個嗎
m3u8文件能合成一個嗎
随着視頻格式發展的多元化,近幾年來新的視頻格式層出不窮。m3u8格式逐漸走進人們的視野中,但是這種是視頻格式僅僅支持在線觀看。要想将視頻下載下來,還需要将視頻轉換為本地視頻,也就是我們常說的mp4視頻。今天就教你一招輕松将m3u8視頻轉換為...
2026-05-14
Copyright 2023-2026 - www.tftnews.com All Rights Reserved