驗證資料工具類目

2021-09-20 05:54:43 字數 3517 閱讀 8660

using

system.text.regularexpressions;

namespace

commons.helpers

#endregion

#region 驗證是否為正整數

//////驗證是否為正整數

/// ///

///public

static

bool isint(string

str)

#endregion

#region 驗證是否符合email格式

//////驗證是否符合email格式

/// ///

要判斷的email字串

///判斷結果

public

static

bool isvalidemail(string

stremail)

public

static

bool isvaliddoemail(string

stremail)

\.[0-9]\.[0-9]\.)|(([\w-]+\.)+))([a-za-z]|[0-9])(\]?)$");

}#endregion

#region 驗證是否是正確的url

//////驗證是否是正確的url

/// ///

要驗證的url

///判斷結果

public

static

bool isurl(string

strurl)

[0-9]|[1-9][0-9]|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]|[1-9][0-9]|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]|[1-9][0-9]|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1][0-9]|[1-9][0-9]|[0-9])|localhost|([a-za-z0-9\-]+\.)*[a-za-z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-za-z]))(\:[0-9]+)*(/($|[a-za-z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$");

}#endregion

#region 驗證是否為ip

//////驗證是否為ip

/// ///

///public

static

bool isip(string

ip) (2[0-4]\d|25[0-5]|[01]?\d\d?)$");

}public

static

bool isipsect(string

ip) ((2[0-4]\d|25[0-5]|[01]?\d\d?|\*)\.)(2[0-4]\d|25[0-5]|[01]?\d\d?|\*)$");

}#endregion

#region 驗證是否為手機號碼

//////驗證是否為手機號碼

/// ///

///public

static

bool ishandset(string

handset)

");}

#endregion

#region 驗證是否為身份證號碼

//////驗證是否為身份證號碼

/// ///

///public

static

bool isidcard(string

idcard)

$)|(^\d$)");

}#endregion

#region 驗證是否是時間格式

//////驗證是否是時間格式

/// ///

public

static

bool istime(string

timeval)

#endregion

#region 檢測是否有sql危險字元

//////檢測是否有sql危險字元

/// ///

要判斷字串

///判斷結果

public

static

bool issafesqlstring(string

str)

|\#endregion

#region 判斷是否為base64字串

//////判斷是否為base64字串

/// ///

///public

static

bool isbase64string(string

str)

#endregion

#region 返回指定ip是否在指定的ip陣列所限定的範圍內

//////返回指定ip是否在指定的ip陣列所限定的範圍內, ip陣列內的ip位址可以使用*表示該ip段任意, 例如192.168.1.*

/// ///

//////

public

static

bool iniparray(string ip, string

iparray)

if (userip.length >i)

else

}else

}if (r == 4

)

}return

false

; }

#endregion

#region 判斷字串是否是yy-mm-dd字串

//////判斷字串是否是yy-mm-dd字串

/// ///

待判斷字串

///判斷結果

public

static

bool isdatestring(string

str)

)-(\d)-(\d)");

}#endregion

#region 驗證是否符合副檔名要求

//////驗證是否符合副檔名要求

/// ///

副檔名字串

///檔名 ///

判斷結果

public

static

bool isvalidfileextensions(string extensions, string

filename)

)$", extensions.replace('

,', '|'

)); regex reg = new regex(strpattern, regexoptions.cultureinvariant |regexoptions.ignorecase);

return

reg.ismatch(filename);

}#endregion

}}

驗證管理類目

using system.text.regularexpressions namespace commons.helpers endregion region 驗證是否為正整數 驗證是否為正整數 public static bool isint string str endregion region...

驗證工具類

public class regexlib 以漢字或字母開頭 漢字與字母數字組合的名稱,長度為4到16位 public static bool isvalidnickname string strin 判斷真實姓名 public static bool isvalidrealname string ...

Android正則驗證工具類

東西不多,但一般專案夠用了。public class regularutil 1 9 d 0 d 1 0 2 0 1 2 d 3 0 1 d 0 9 x 驗證郵箱 public static final string regex email a z0 9a z a z0 9a z a z0 9a z...