Bài viết chỉ mang tính chất tổng hợp từ từ
- Kiểm tra mật khẩu: từ 8->15 ký tự,chứa 1 nhất : 1 hoa. 1 thường, 1 ký tự đặc biệt
1 2 3 4 5 6 7 8 9 10 11 12 13 | /// <summary> /// /// từ 8->15 ký tự,chứa 1 nhất : 1 hoa. 1 thường, 1 ký tự đặc biệt, 1 số /// </summary> /// <param name="pass"></param> /// <returns>Boolean</returns> public static Boolean checkPassHash(string pass) { var passValidation = new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*d)(?=.*[^da-zA-Z]).{8,15}$"); ////var passValidation = new Regex(@"^(?=.*[a-z])(?=.*[A-Z])(?=.*d)(?=.*[^da-zA-Z]).{8,}$");///Yêu cầu mật khẩu ít nhất 8 kí tự bao gồm chữ hoa, chữ thường, chữ số và kí tự đặc biệt, 1 số. return passValidation.IsMatch(pass); } |
- Kiểm tra hợp lệ ngày tháng
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | /// <summary> /// Chuyển chuỗi ngày tháng năm [giờ phút giây] thành đối tượng DateTime /// </summary> /// <param name="inputString">chuỗi ngày tháng, định dạng dd/MM/yyyy hoặc dd-MM-yyyy (nếu có giờ thì thêm theo định dạng ' HH:mm:ss')</param> /// <param name="outputDateTime">kết quả ngày sau khi chuyển</param> /// <param name="formatString">định dạng riêng nếu có</param> /// <returns>true nếu chuyển được, false là chuyển thất bại</returns> public static bool DateStringToDateTime(string inputString, out DateTime outputDateTime, string formatString = "") { outputDateTime = DateTime.MinValue; if (string.IsNullOrEmpty(inputString)) return false; inputString = inputString.Trim(); bool coGio = false; string format = ""; if (!string.IsNullOrEmpty(formatString)) format = formatString; else { if (inputString.Contains('-')) format = "dd-MM-yyyy"; if (inputString.Contains('/')) format = "dd/MM/yyyy"; if (inputString.Contains(' ')) coGio = true; } if (coGio) { if (DateTime.TryParseExact(inputString, format + " HH:mm:ss", null, DateTimeStyles.None, out outputDateTime)) return true; if (DateTime.TryParseExact(inputString, format + " HH:mm", null, DateTimeStyles.None, out outputDateTime)) return true; if (DateTime.TryParseExact(inputString, format + " HH", null, DateTimeStyles.None, out outputDateTime)) return true; return false; } else { if (DateTime.TryParseExact(inputString, format, null, DateTimeStyles.None, out outputDateTime)) return true; return false; } } |