正規表示式收藏

2021-04-02 14:41:10 字數 3361 閱讀 1039

【日期的驗證表示式】

a.以下正確的輸入格式: [2004-2-29], [2004-02-29 10:29:39 pm], [2004/12/31]

^((/d(([02468][048])|([13579][26]))[/-///s]?((((0?[13578])|(1[02]))[/-///s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[/-///s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[/-///s]?((0?[1-9])|([1-2][0-9])))))|(/d(([02468][1235679])|([13579][01345789]))[/-///s]?((((0?[13578])|(1[02]))[/-///s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[/-///s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[/-///s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))(/s(((0?[1-9])|(1[0-2]))/:([0-5][0-9])((/s)|(/:([0-5][0-9])/s))([am|pm|am|pm])))?$

具體使用:

日期:

validationexpression="^[a-za-z0-9]$"

validationexpression="^[a-za-z0-9_9/-]+@[a-za-z0-9]/.[a-za-z0-9][/.]?[a-za-z0-9][/.]?[a-za-z0-9]$"

判斷日期2      2004-04-30 00:00:00

//日期部分

regex += @"(/s(((0?[0-9])|([1-2][0-3]))/:([0-5]?[0-9])((/s)|(/:([0-5]?[0-9])))))?$";

//時間部分

system.text.regularexpressions.regexoptions options = ((system.text.regularexpressions.regexoptions.ignorepatternwhitespace | system.text.regularexpressions.regexoptions.multiline) | system.text.regularexpressions.regexoptions.ignorecase);

system.text.regularexpressions.regex reg = new system.text.regularexpressions.regex(regex, options);

string s = "2003-02-29 23:59:59";

system.console.out.writeline(s + " ",reg.i**atch(s));

s = "2004-02-29 23:59:59";

system.console.out.writeline(s + " ",reg.i**atch(s));

s = "2004-04-30 0:59:59";

system.console.out.writeline(s + " ",reg.i**atch(s));

s = "2004-04-30 01:11:0";

system.console.out.writeline(s + " ",reg.i**atch(s));

s = "2004-04-30 0:0:0";

system.console.out.writeline(s + " ",reg.i**atch(s));

s = "2004-04-30 00:00:00";

system.console.out.writeline(s + " ",reg.i**atch(s));}}

判斷輸入的是否全是數字/字母.

using system.text.regularexpressions;

private void button3_click(object sender, system.eventargs e)

system.text.regularexpressions.regex strregex2 = new regex(@"[a-z]",regexoptions.ignorecase);

if(strregex2.matches(str).count == str.length)

}

正規表示式收藏

日期的驗證表示式 a.以下正確的輸入格式 2004 2 29 2004 02 29 10 29 39 pm 2004 12 31 d 02468 048 13579 26 s 0?13578 1 02 s 0?1 9 1 2 0 9 3 01 0?469 11 s 0?1 9 1 2 0 9 30 ...

正規表示式收藏

1.由數字 26個英文字母或者下劃線組成的字串 0 9a za z 2.非負整數 正整數 0 d 3.正整數 0 9 1 9 0 9 4.非正整數 負整數 0 d 0 5.負整數 0 9 1 9 0 9 6.整數 d 7.非負浮點數 正浮點數 0 d d 8.正浮點數 0 9 0 9 1 9 0 9...

正規表示式收藏

一個好的 有很多正規表示式 還有如下的收藏,來自 匹配中文字元的正規表示式 u4e00 u9fa5 評註 匹配中文還真是個頭疼的事,有了這個表示式就好辦了 匹配雙位元組字元 包括漢字在內 x00 xff 評註 可以用來計算字串的長度 一個雙位元組字元長度計2,ascii字元計1 字串中只能輸入漢字 ...

收藏 種正規表示式

d 非負整數 正整數 0 0 9 1 9 0 9 正整數 d 0 非正整數 負整數 0 0 9 1 9 0 9 負整數 d 整數 d d 非負浮點數 正浮點數 0 0 9 0 9 1 9 0 9 0 9 1 9 0 9 0 9 0 9 1 9 0 9 正浮點數 d d 0 0 非正浮點數 負浮點數 ...

正規表示式的收藏

d 非負整數 正整數 0 0 9 1 9 0 9 正整數 d 0 非正整數 負整數 0 0 9 1 9 0 9 負整數 d 整數 d d 非負浮點數 正浮點數 0 0 9 0 9 1 9 0 9 0 9 1 9 0 9 0 9 0 9 1 9 0 9 正浮點數 d d 0 0 非正浮點數 負浮點數 ...