Skip to content

Class Validator

Namespace: Tool.Utils
Assembly: Tool.Net.dll

相关正则类(包含常用的正则表达式)高达65种供大家参考学习,使用。

csharp
public class Validator

Inheritance

objectValidator

Inherited Members

object.Equals(object?), object.Equals(object?, object?), object.GetHashCode(), object.GetType(), object.MemberwiseClone(), object.ReferenceEquals(object?, object?), object.ToString()

Extension Methods

ObjectExtension.Add<T>(object, object, object), ObjectExtension.CopyEntity(object, object, params string[]), ObjectExtension.EntityToJson(object), ObjectExtension.EntityToJson(object, bool), ObjectExtension.EntityToJson(object, bool, string), DictionaryExtension.GetDictionary(object), TypeExtension.GetFieldKey(object, string, out bool), TypeExtension.GetFieldKey<T>(object, string, out bool), TypeExtension.GetFieldKey(object, Type, string, out bool), ObjectExtension.GetIntPtr(object), ObjectExtension.GetIntPtrInt(object), TypeExtension.GetPropertieFind(object, string, bool), TypeExtension.GetProperties(object), TypeExtension.GetPropertyKey(object, string, out bool), TypeExtension.GetPropertyKey<T>(object, string, out bool), TypeExtension.GetPropertyKey(object, Type, string, out bool), TypeExtension.GetValue(object, PropertyDescriptor), TypeExtension.GetValue(object, string, bool), TypeExtension.GetValue(object, string), ObjectExtension.Read<T>(object, object, int, int), ObjectExtension.Read<T>(object, int, object, int, int), DictionaryExtension.SetDictionary(object, IDictionary<string, object>), TypeExtension.SetFieldKey(object, string, object), TypeExtension.SetFieldKey<T>(object, string, object), TypeExtension.SetFieldKey(object, Type, string, object), TypeExtension.SetPropertyKey(object, string, object), TypeExtension.SetPropertyKey<T>(object, string, object), TypeExtension.SetPropertyKey(object, Type, string, object), TypeExtension.SetValue(object, PropertyDescriptor, object), TypeExtension.SetValue(object, string, object, bool), TypeExtension.SetValue(object, string, object), ObjectExtension.ToBase64String(object), ObjectExtension.ToBytes(object), ObjectExtension.ToBytes(object, out Type), DictionaryExtension.ToDictionary(object), DictionaryExtension.ToDictionary<T>(object), DictionaryExtension.ToIDictionary(object), DictionaryExtension.ToIDictionary<T>(object), ObjectExtension.ToJson(object), ObjectExtension.ToJson(object, JsonSerializerOptions), ObjectExtension.ToJsonWeb(object), ObjectExtension.ToJsonWeb(object, Action<JsonSerializerOptions>), ObjectExtension.ToTryVar<T>(object, T), ObjectExtension.ToVar<T>(object), ObjectExtension.ToVar(object, Type, bool), ObjectExtension.ToVar(object, string), ObjectExtension.ToXml(object)

Remarks

代码由逆血提供支持

Fields

reg

数字

csharp
public const string reg = "^[0-9]*$"

Field Value

string

reg1

n位的数字

csharp
public const string reg1 = "^\\d{n}$"

Field Value

string

reg10

非零的正整数

csharp
public const string reg10 = "^[1-9]\\d*$"

Field Value

string

reg10_1

非零的正整数

csharp
public const string reg10_1 = "^([1-9][0-9]*){1,3}$"

Field Value

string

reg10_2

非零的正整数

csharp
public const string reg10_2 = "^\\+?[1-9][0-9]*$"

Field Value

string

reg11

非零的负整数

csharp
public const string reg11 = "^\\-[1-9][]0-9″*$"

Field Value

string

reg11_1

非零的负整数

csharp
public const string reg11_1 = "^-[1-9]\\d*$"

Field Value

string

reg12

非负整数

csharp
public const string reg12 = "^\\d+$"

Field Value

string

reg12_1

非负整数

csharp
public const string reg12_1 = "^[1-9]\\d*|0$"

Field Value

string

reg13

非正整数

csharp
public const string reg13 = "^-[1-9]\\d*|0$"

Field Value

string

reg13_1

非正整数

csharp
public const string reg13_1 = "^((-\\d+)|(0+))$"

Field Value

string

reg14

非负浮点数

csharp
public const string reg14 = "^\\d+(\\.\\d+)?$"

Field Value

string

reg14_1

非负浮点数

csharp
public const string reg14_1 = "^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*|0?\\.0+|0$"

Field Value

string

reg15

非正浮点数

csharp
public const string reg15 = "^((-\\d+(\\.\\d+)?)|(0+(\\.0+)?))$"

Field Value

string

reg15_1

非正浮点数

csharp
public const string reg15_1 = "^(-([1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*))|0?\\.0+|0$"

Field Value

string

reg16

正浮点数

csharp
public const string reg16 = "^[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*$"

Field Value

string

reg16_1

正浮点数

csharp
public const string reg16_1 = "^(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*))$"

Field Value

string

reg17

负浮点数

csharp
public const string reg17 = "^-([1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*)$"

Field Value

string

reg17_1

负浮点数

csharp
public const string reg17_1 = "^(-(([0-9]+\\.[0-9]*[1-9][0-9]*)|([0-9]*[1-9][0-9]*\\.[0-9]+)|([0-9]*[1-9][0-9]*)))$"

Field Value

string

reg18

浮点数

csharp
public const string reg18 = "^(-?\\d+)(\\.\\d+)?$"

Field Value

string

reg18_1

浮点数

csharp
public const string reg18_1 = "^-?([1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*|0?\\.0+|0)$"

Field Value

string

reg19

汉字

csharp
public const string reg19 = "^[\\u4e00-\\u9fa5]{0,}$"

Field Value

string

reg2

至少n位的数字

csharp
public const string reg2 = "^\\d{n,}$"

Field Value

string

reg20

英文和数字

csharp
public const string reg20 = "^[A-Za-z0-9]+$"

Field Value

string

reg20_1

英文和数字

csharp
public const string reg20_1 = "^[A-Za-z0-9]{4,40}$"

Field Value

string

reg21

长度为3-20的所有字符

csharp
public const string reg21 = "^.{3,20}$"

Field Value

string

reg22

由26个英文字母组成的字符串

csharp
public const string reg22 = "^[A-Za-z]+$"

Field Value

string

reg23

由26个大写英文字母组成的字符串

csharp
public const string reg23 = "^[A-Z]+$"

Field Value

string

reg24

由26个小写英文字母组成的字符串

csharp
public const string reg24 = "^[a-z]+$"

Field Value

string

reg25

由数字和26个英文字母组成的字符串

csharp
public const string reg25 = "^[A-Za-z0-9]+$"

Field Value

string

reg26

由数字、26个英文字母或者下划线组成的字符串

csharp
public const string reg26 = "^\\w+$"

Field Value

string

reg26_1

由数字、26个英文字母或者下划线组成的字符串

csharp
public const string reg26_1 = "^\\w{3,20}$"

Field Value

string

reg27

中文、英文、数字包括下划线

csharp
public const string reg27 = "^[\\u4E00-\\u9FA5A-Za-z0-9_]+$"

Field Value

string

reg28

中文、英文、数字但不包括下划线等符号

csharp
public const string reg28 = "^[\\u4E00-\\u9FA5A-Za-z0-9]+$"

Field Value

string

reg28_1

中文、英文、数字但不包括下划线等符号

csharp
public const string reg28_1 = "^[\\u4E00-\\u9FA5A-Za-z0-9]{2,20}$"

Field Value

string

reg29

可以输入含有^%’,;=?$\”等字符

csharp
public const string reg29 = "[^%&’,;=?$\\x22]+"

Field Value

string

reg3

m-n位的数字

csharp
public const string reg3 = "^\\d{m,n}$"

Field Value

string

reg30

禁止输入含有~的字符

csharp
public const string reg30 = "[^~\\x22]+"

Field Value

string

reg31

Email地址

csharp
public const string reg31 = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$"

Field Value

string

reg32

域名

csharp
public const string reg32 = "[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(/.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+/.?"

Field Value

string

reg33

InternetURL

csharp
public const string reg33 = "[a-zA-z]+://[^\\s]*"

Field Value

string

reg33_1

InternetURL

csharp
public const string reg33_1 = "^http://([\\w-]+\\.)+[\\w-]+(/[\\w-./?%&=]*)?$"

Field Value

string

reg34

手机号码

csharp
public const string reg34 = "^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\\d{8}$"

Field Value

string

reg35

电话号码(“XXX-XXXXXXX”、”XXXX-XXXXXXXX”、”XXX-XXXXXXX”、”XXX-XXXXXXXX”、”XXXXXXX”和”XXXXXXXX)

csharp
public const string reg35 = "^($$\\d{3,4}-)|\\d{3.4}-)?\\d{7,8}$"

Field Value

string

reg36

国内电话号码(0511-4405222、021-87888822)

csharp
public const string reg36 = "\\d{3}-\\d{8}|\\d{4}-\\d{7}"

Field Value

string

reg37

身份证号(15位、18位数字)

csharp
public const string reg37 = "^\\d{15}|\\d{18}$"

Field Value

string

reg38

短身份证号码(数字、字母x结尾)

csharp
public const string reg38 = "^([0-9]){7,18}(x|X)?$"

Field Value

string

reg38_1

短身份证号码(数字、字母x结尾)

csharp
public const string reg38_1 = "^\\d{8,18}|[0-9x]{8,18}|[0-9X]{8,18}?$"

Field Value

string

reg39

帐号是否合法(字母开头,允许5-16字节,允许字母数字下划线)

csharp
public const string reg39 = "^[a-zA-Z][a-zA-Z0-9_]{4,15}$"

Field Value

string

reg4

零和非零开头的数字

csharp
public const string reg4 = "^(0|[1-9][0-9]*)$"

Field Value

string

reg40

密码(以字母开头,长度在6~18之间,只能包含字母、数字和下划线)

csharp
public const string reg40 = "^[a-zA-Z]\\w{5,17}$"

Field Value

string

reg41

强密码(必须包含大小写字母和数字的组合,不能使用特殊字符,长度在8-10之间)

csharp
public const string reg41 = "^(?=.*\\d)(?=.*[a-z])(?=.*[A-Z]).{8,10}$"

Field Value

string

reg42

日期格式

csharp
public const string reg42 = "^\\d{4}-\\d{1,2}-\\d{1,2}"

Field Value

string

reg43

一年的12个月(01~09和1~12)

csharp
public const string reg43 = "^(0?[1-9]|1[0-2])$"

Field Value

string

reg44

一个月的31天(01~09和1~31)

csharp
public const string reg44 = "^((0?[1-9])|((1|2)[0-9])|30|31)$"

Field Value

string

reg45

钱的输入格式: 有四种钱的表示形式我们可以接受:”10000.00″ 和 “10,000.00”, 和没有 “分” 的 “10000” 和 “10,000”

csharp
public const string reg45 = "^[1-9][0-9]*$"

Field Value

string

reg46

这表示任意一个不以0开头的数字,但是,这也意味着一个字符”0″不通过,所以我们采用下面的形式

csharp
public const string reg46 = "^(0|[1-9][0-9]*)$"

Field Value

string

reg47

一个0或者一个不以0开头的数字.我们还可以允许开头有一个负号

csharp
public const string reg47 = "^(0|-?[1-9][0-9]*)$"

Field Value

string

reg48

这表示一个0或者一个可能为负的开头不为0的数字.让用户以0开头好了.把负号的也去掉,因为钱总不能是负的吧.下面我们要加的是说明可能的小数部分

csharp
public const string reg48 = "^[0-9]+(.[0-9]+)?$"

Field Value

string

reg49

必须说明的是,小数点后面至少应该有1位数,所以”10.”是不通过的,但是 “10” 和 “10.2” 是通过的

csharp
public const string reg49 = "^[0-9]+(.[0-9]{2})?$"

Field Value

string

reg5

非零开头的最多带两位小数的数字

csharp
public const string reg5 = "^([1-9][0-9]*)+(.[0-9]{1,2})?$"

Field Value

string

reg50

这样我们规定小数点后面必须有两位,如果你认为太苛刻了,可以这样

csharp
public const string reg50 = "^[0-9]+(.[0-9]{1,2})?$"

Field Value

string

reg51

这样就允许用户只写一位小数。下面我们该考虑数字中的逗号了,我们可以这样

csharp
public const string reg51 = "^[0-9]{1,3}(,[0-9]{3})*(.[0-9]{1,2})?$"

Field Value

string

reg52

1到3个数字,后面跟着任意个 逗号+3个数字,逗号成为可选,而不是必须

csharp
public const string reg52 = "^([0-9]+|[0-9]{1,3}(,[0-9]{3})*)(.[0-9]{1,2})?$"

Field Value

string

reg53

备注:这就是最终结果了,别忘了”+”可以用”*”替代。如果你觉得空字符串也可以接受的话(奇怪,为什么?)最后,别忘了在用函数时去掉去掉那个反斜杠,一般的错误都在这里 xml文件

csharp
public const string reg53 = "^([a-zA-Z]+-?)+[a-zA-Z0-9]+\\\\.[x|X][m|M][l|L]$"

Field Value

string

reg54

中文字符的正则表达式

csharp
public const string reg54 = "[\\u4e00-\\u9fa5]"

Field Value

string

reg55

双字节字符 (包括汉字在内,可以用来计算字符串的长度(一个双字节字符长度计2,ASCII字符计1))

csharp
public const string reg55 = "[^\\x00-\\xff]"

Field Value

string

reg56

空白行的正则表达式,可用来删除空白行

csharp
public const string reg56 = "\\n\\s*\\r"

Field Value

string

reg57

HTML标记的正则表达式

csharp
public const string reg57 = "<(\\S*?)[^>]*>.*?</\\1>|<.*? />"

Field Value

string

reg58

首尾空白字符的正则表达式

csharp
public const string reg58 = "^\\s*|\\s*$)"

Field Value

string

reg58_1

首尾空白字符的正则表达式

csharp
public const string reg58_1 = "(^\\s*)|(\\s*$"

Field Value

string

reg59

腾讯QQ号

csharp
public const string reg59 = "[1-9][0-9]{4,}"

Field Value

string

reg6

带1-2位小数的正数或负数

csharp
public const string reg6 = "^(\\-)?\\d+(\\.\\d{1,2})?$"

Field Value

string

reg60

中国邮政编码

csharp
public const string reg60 = "[1-9]\\d{5}(?!\\d)"

Field Value

string

reg61

IP地址

csharp
public const string reg61 = "\\d+\\.\\d+\\.\\d+\\.\\d+"

Field Value

string

reg62

IP地址

csharp
public const string reg62 = "((?:(?:25[0-5]|2[0-4]\\\\d|[01]?\\\\d?\\\\d)\\\\.){3}(?:25[0-5]|2[0-4]\\\\d|[01]?\\\\d?\\\\d))"

Field Value

string

reg63

提取[]的值

csharp
public const string reg63 = "(?is)(?<=\\[)(.*)(?=\\])"

Field Value

string

reg64

提取()的值

csharp
public const string reg64 = "(?is)(?<=\\()(.*)(?=\\))"

Field Value

string

reg65

提取{}的值

csharp
public const string reg65 = "(?is)(?<=\\{)(.*)(?=\\})"

Field Value

string

reg7

正数、负数、和小数

csharp
public const string reg7 = "^(\\-|\\+)?\\d+(\\.\\d+)?$"

Field Value

string

reg8

有两位小数的正实数

csharp
public const string reg8 = "^[0-9]+(.[0-9]{2})?$"

Field Value

string

reg9

有1~3位小数的正实数

csharp
public const string reg9 = "^[0-9]+(.[0-9]{1,3})?$"

Field Value

string

Methods

IsChineseCharacter(string)

验证只包含汉字

csharp
public static bool IsChineseCharacter(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsDateTime(string)

验证日期

csharp
public static bool IsDateTime(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsDecimal(string)

验证小数

csharp
public static bool IsDecimal(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsEmail(string)

验证电子邮箱
[@字符前可以包含字母、数字、下划线和点号;@字符后可以包含字母、数字、下划线和点号;@字符后至少包含一个点号且点号不能是最后一个字符;最后一个点号后只能是字母或数字]

csharp
public static bool IsEmail(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsEnglishCharacter(string)

验证只包含英文字母

csharp
public static bool IsEnglishCharacter(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsIDCard(string)

验证身份证号(不区分一二代身份证号)

csharp
public static bool IsIDCard(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsIDCard15(string)

验证一代身份证号(15位数)
[长度为15位的数字;匹配对应省份地址;生日能正确匹配]

csharp
public static bool IsIDCard15(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsIDCard18(string)

验证二代身份证号(18位数,GB11643-1999标准)
[长度为18位;前17位为数字,最后一位(校验码)可以为大小写x;匹配对应省份地址;生日能正确匹配;校验码能正确匹配]

csharp
public static bool IsIDCard18(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsIPv4(string)

验证IPv4地址
[第一位和最后一位数字不能是0或255;允许用0补位]

csharp
public static bool IsIPv4(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsIPv6(string)

验证IPv6地址
[可用于匹配任何一个合法的IPv6地址]

csharp
public static bool IsIPv6(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsInteger(string)

验证整数

csharp
public static bool IsInteger(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsIntegerAndEnglishCharacter(string)

验证只包含数字和英文字母

csharp
public static bool IsIntegerAndEnglishCharacter(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsIntegerLength(string, int, int)

验证数字长度范围(数字前端的0计长度)
[若要验证固定长度,可传入相同的两个长度数值]

csharp
public static bool IsIntegerLength(string input, int lengthBegin, int lengthEnd)

Parameters

input string

待验证的字符串

lengthBegin int

长度范围起始值(含)

lengthEnd int

长度范围结束值(含)

Returns

bool

是否匹配

IsIntegerNotNagtive(string)

验证非负整数

csharp
public static bool IsIntegerNotNagtive(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsIntegerPositive(string)

验证正整数

csharp
public static bool IsIntegerPositive(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsLatitude(string)

验证纬度

csharp
public static bool IsLatitude(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsLongitude(string)

验证经度

csharp
public static bool IsLongitude(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsMatch(string, string)

验证字符串是否匹配正则表达式描述的规则

csharp
public static bool IsMatch(string inputStr, string patternStr)

Parameters

inputStr string

待验证的字符串

patternStr string

正则表达式字符串

Returns

bool

是否匹配

IsMatch(string, string, bool)

验证字符串是否匹配正则表达式描述的规则

csharp
public static bool IsMatch(string inputStr, string patternStr, bool ifIgnoreCase = true)

Parameters

inputStr string

待验证的字符串

patternStr string

正则表达式字符串

ifIgnoreCase bool

匹配时是否不区分大小写

Returns

bool

是否匹配

IsMatch(string, bool, string)

验证字符串是否匹配正则表达式描述的规则

csharp
public static bool IsMatch(string inputStr, bool ifValidateWhiteSpace, string patternStr)

Parameters

inputStr string

待验证的字符串

ifValidateWhiteSpace bool

是否验证空白字符串

patternStr string

正则表达式字符串

Returns

bool

是否匹配

IsMatch(string, string, bool, bool)

验证字符串是否匹配正则表达式描述的规则

csharp
public static bool IsMatch(string inputStr, string patternStr, bool ifIgnoreCase, bool ifValidateWhiteSpace)

Parameters

inputStr string

待验证的字符串

patternStr string

正则表达式字符串

ifIgnoreCase bool

匹配时是否不区分大小写

ifValidateWhiteSpace bool

是否验证空白字符串

Returns

bool

是否匹配

IsMobilePhoneNumber(string)

验证手机号码
[可匹配"(+86)013325656352",括号可以省略,+号可以省略,(+86)可以省略,11位手机号前的0可以省略;11位手机号第二位数可以是3、4、5、8中的任意一个]

csharp
public static bool IsMobilePhoneNumber(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsNumber(string)

验证数字(double类型)
[可以包含负号和小数点]

csharp
public static bool IsNumber(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsPhoneNumber(string)

验证电话号码(可以是固定电话号码或手机号码)
[固定电话:[3位或4位区号;区号可以用小括号括起来;区号可以省略;区号与本地号间可以用减号或空格隔开;可以有3位数的分机号,分机号前要加减号]]
[手机号码:[可匹配"(+86)013325656352",括号可以省略,+号可以省略,(+86)可以省略,手机号前的0可以省略;手机号第二位数可以是3、4、5、8中的任意一个]]

csharp
public static bool IsPhoneNumber(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsStringByteLength(string, int, int)

验证字符串字节数长度范围
[若要验证固定长度,可传入相同的两个长度数值;每个汉字为两个字节长度]

csharp
public static bool IsStringByteLength(string input, int lengthBegin, int lengthEnd)

Parameters

input string

待验证的字符串

lengthBegin int

长度范围起始值(含)

lengthEnd int

长度范围结束值(含)

Returns

bool

IsStringInclude(string, bool, bool, bool)

验证字符串包含内容

csharp
public static bool IsStringInclude(string input, bool withEnglishCharacter, bool withNumber, bool withChineseCharacter)

Parameters

input string

待验证的字符串

withEnglishCharacter bool

是否包含英文字母

withNumber bool

是否包含数字

withChineseCharacter bool

是否包含汉字

Returns

bool

是否匹配

IsStringLength(string, int, int)

验证字符串长度范围
[若要验证固定长度,可传入相同的两个长度数值]

csharp
public static bool IsStringLength(string input, int lengthBegin, int lengthEnd)

Parameters

input string

待验证的字符串

lengthBegin int

长度范围起始值(含)

lengthEnd int

长度范围结束值(含)

Returns

bool

是否匹配

IsStringLengthByInclude(string, bool, bool, bool, int, int)

验证字符串长度范围
[若要验证固定长度,可传入相同的两个长度数值]

csharp
public static bool IsStringLengthByInclude(string input, bool withEnglishCharacter, bool withNumber, bool withChineseCharacter, int lengthBegin, int lengthEnd)

Parameters

input string

待验证的字符串

withEnglishCharacter bool

是否包含英文字母

withNumber bool

是否包含数字

withChineseCharacter bool

是否包含汉字

lengthBegin int

长度范围起始值(含)

lengthEnd int

长度范围结束值(含)

Returns

bool

是否匹配

IsStringLengthOnlyNumberAndEnglishCharacter(string, int, int)

验证字符串长度范围(字符串内只包含数字和/或英文字母)
[若要验证固定长度,可传入相同的两个长度数值]

csharp
public static bool IsStringLengthOnlyNumberAndEnglishCharacter(string input, int lengthBegin, int lengthEnd)

Parameters

input string

待验证的字符串

lengthBegin int

长度范围起始值(含)

lengthEnd int

长度范围结束值(含)

Returns

bool

是否匹配

IsTelePhoneNumber(string)

验证固定电话号码
[3位或4位区号;区号可以用小括号括起来;区号可以省略;区号与本地号间可以用减号或空格隔开;可以有3位数的分机号,分机号前要加减号]

csharp
public static bool IsTelePhoneNumber(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsURL(string)

验证网址(可以匹配IPv4地址但没对IPv4地址进行格式验证;IPv6暂时没做匹配)
[允许省略"😕/";可以添加端口号;允许层级;允许传参;域名中至少一个点号且此点号前要有内容]

csharp
public static bool IsURL(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

IsZipCode(string)

验证邮政编码

csharp
public static bool IsZipCode(string input)

Parameters

input string

待验证的字符串

Returns

bool

是否匹配

基于Apache-2.0协议开源