71 lines
2.8 KiB
C#
71 lines
2.8 KiB
C#
using System.Text.RegularExpressions;
|
|
namespace Common.Validation
|
|
{
|
|
public static class FixedValidation
|
|
{
|
|
public static bool CheckLawPassword(this string password, ref List<string> errors)
|
|
{
|
|
bool ret = true;
|
|
if (password.Length != 6)
|
|
{
|
|
errors.Add("کلمه عبور باید حداقل 6 گاراکتر باشد");
|
|
ret = false;
|
|
}
|
|
|
|
// بررسی شامل بودن حداقل یک حرف
|
|
if (!Regex.IsMatch(password, "[a-zA-Z]"))
|
|
{
|
|
errors.Add("کلمه عبور باید حداقل شامل یک حرف انگلیسی بزرگ یا کوچک باشد");
|
|
|
|
ret = false;
|
|
}
|
|
// بررسی شامل بودن حداقل یک عدد
|
|
if (!Regex.IsMatch(password, "[0-9]"))
|
|
{
|
|
errors.Add("کلمه عبور باید حداقل شامل یک عدد باشد");
|
|
ret = false;
|
|
}
|
|
// بررسی اینکه فقط حروف و اعداد انگلیسی باشد
|
|
if(Regex.IsMatch(password, "^[a-zA-Z0-9]+$"))
|
|
{
|
|
errors.Add("کلمه عبور فقط عدد و حروف انگلیسی مجاز است");
|
|
ret = false;
|
|
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
public static bool CheckUsername(this string Username)
|
|
=> (Username.Length == 11 && Username.StartsWith("09"))
|
|
|| (Username.Length == 9 && Username.StartsWith("E/"));
|
|
public static bool CheckMobile(this string Mobile) => Mobile.Length == 11 && Mobile.StartsWith("09");
|
|
public static bool IsValidEmail(this string email)
|
|
{
|
|
// الگوی ساده اما معتبر برای بررسی ایمیل
|
|
string pattern = @"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$";
|
|
|
|
return Regex.IsMatch(email, pattern);
|
|
}
|
|
public static bool IsOnlyPersianLetters(this string input)
|
|
{
|
|
// این الگو فقط اجازه حروف فارسی میدهد
|
|
string pattern = @"^[\u0600-\u06FF\s]+$";
|
|
|
|
return Regex.IsMatch(input, pattern);
|
|
}
|
|
public static bool IsValidWebsite(this string url)
|
|
{
|
|
// پروتکل اختیاری است، فقط باید دامنه درست باشد
|
|
string pattern = @"^(https?:\/\/)?(www\.)?[a-zA-Z0-9\-]+\.[a-zA-Z]{2,}(\S*)?$";
|
|
return Regex.IsMatch(url, pattern);
|
|
}
|
|
public static bool IsValidImage(this byte[] imageData, int maxSizeInBytes = 5 * 1024 * 1024)
|
|
{
|
|
// بررسی خالی بودن یا حجم بیش از حد
|
|
return imageData.Length <= maxSizeInBytes;
|
|
|
|
|
|
}
|
|
}
|
|
}
|