Example #1
0
        private static InputParam CheckNgayThang(string input)
        {
            var inputParam = new InputParam
            {
                InputType = InputType.NgayThang
            };
            const string pattern = @"^\d{1,2}\/\d{1,2}\/\d\d\d\d$";

            if (Regex.IsMatch(input, pattern))
            {
                var dateStrings = input.Trim().Split('/');
                try
                {
                    // ReSharper disable once ObjectCreationAsStatement
                    new DateTime(int.Parse(dateStrings[2]), int.Parse(dateStrings[1]), int.Parse(dateStrings[0]));
                    inputParam.Result   = true;
                    inputParam.MsgError = "Không lỗi";
                }
                catch (Exception)
                {
                    inputParam.Result   = false;
                    inputParam.MsgError = "Ngày này không tồn tại";
                }
                //inputParam.Result = true;
                //inputParam.MsgError = "Không lỗi";
            }
            else
            {
                inputParam.Result   = false;
                inputParam.MsgError = "Không phải ngày tháng";
            }
            return(inputParam);
        }
Example #2
0
        private static InputParam Checkmail(string input)
        {
            var inputparm = new InputParam {
                InputType = InputType.Email
            };
            const string pattern = @"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9]+(\.[a-z]{2,6})?(\.[a-z]{2,6})$";

            if (Regex.IsMatch(input, pattern))
            {
                inputparm.Result   = true;
                inputparm.MsgError = "Không lỗi";
            }
            else
            {
                inputparm.Result   = false;
                inputparm.MsgError = "Không đúng định dạng Email";
            }
            return(inputparm);
        }
Example #3
0
        private static InputParam CheckSoNguyenDuong(string input)
        {
            var inputparam = new InputParam
            {
                InputType = InputType.SoNguyenDuong
            };
            const string pattern = @"^\d*$";

            if (Regex.IsMatch(pattern, input))
            {
                inputparam.Result   = true;
                inputparam.MsgError = "Không lỗi";
            }
            else
            {
                inputparam.Result   = false;
                inputparam.MsgError = "Không phải số nguyên";
            }
            return(inputparam);
        }
Example #4
0
        private static InputParam CheckSoThucKhongAm(string input)
        {
            var inputparm = new InputParam
            {
                InputType = InputType.SoThucDuong
            };
            const string pattern = @"^\d*\.?\d*$";

            if (Regex.IsMatch(input, pattern))
            {
                inputparm.Result   = true;
                inputparm.MsgError = "Không lỗi";
            }
            else
            {
                inputparm.Result   = false;
                inputparm.MsgError = "Không phải số thực hoặc giá trị âm";
            }
            return(inputparm);
        }
Example #5
0
        private static InputParam CheckSoThuc(string input)
        {
            var inputParam = new InputParam
            {
                InputType = InputType.SoThuc
            };
            const string pattern = @"^-?\d*\.?\d*$";

            if (Regex.IsMatch(input, pattern))
            {
                inputParam.Result   = true;
                inputParam.MsgError = "Không lỗi";
            }
            else
            {
                inputParam.Result   = false;
                inputParam.MsgError = "Không phải số thực";
            }
            return(inputParam);
        }
Example #6
0
 /// <summary>
 /// Kiểm tra 1 textbox truyền vào có hợp lệ không
 /// </summary>
 /// <param name="txtname">truyền vào 1 textbox</param>
 /// <param name="input">truyền vào kiểu kiểm tra</param>
 /// <returns></returns>
 public InputParam CheckTextbox(TextBox txtname, InputType input)
 {
     var inputparam = new InputParam
     {
         Input = txtname.Text,
         InputType = input
     };
     var validate = new ValidateData();
     return ValidateData.ValDataOne(inputparam);
 }
Example #7
0
 private static InputParam CheckSoThucKhongAm(string input)
 {
     var inputparm = new InputParam
     {
         InputType = InputType.SoThucDuong
     };
     const string pattern = @"^\d*\.?\d*$";
     if (Regex.IsMatch(input, pattern))
     {
         inputparm.Result = true;
         inputparm.MsgError = "Không lỗi";
     }
     else
     {
         inputparm.Result = false;
         inputparm.MsgError = "Không phải số thực hoặc giá trị âm";
     }
     return inputparm;
 }
Example #8
0
 private static InputParam CheckSoThuc(string input)
 {
     var inputParam = new InputParam
     {
         InputType = InputType.SoThuc
     };
     const string pattern = @"^-?\d*\.?\d*$";
     if (Regex.IsMatch(input, pattern))
     {
         inputParam.Result = true;
         inputParam.MsgError = "Không lỗi";
     }
     else
     {
         inputParam.Result = false;
         inputParam.MsgError = "Không phải số thực";
     }
     return inputParam;
 }
Example #9
0
 private static InputParam CheckSoNguyenDuong(string input)
 {
     var inputparam = new InputParam
     {
         InputType = InputType.SoNguyenDuong
     };
     const string pattern = @"^\d*$";
     if (Regex.IsMatch(pattern, input))
     {
         inputparam.Result = true;
         inputparam.MsgError = "Không lỗi";
     }
     else
     {
         inputparam.Result = false;
         inputparam.MsgError = "Không phải số nguyên";
     }
     return inputparam;
 }
Example #10
0
 private static InputParam CheckNgayThang(string input)
 {
     var inputParam = new InputParam
     {
         InputType = InputType.NgayThang
     };
     const string pattern = @"^\d{1,2}\/\d{1,2}\/\d\d\d\d$";
     if (Regex.IsMatch(input, pattern))
     {
         var dateStrings = input.Trim().Split('/');
         try
         {
             // ReSharper disable once ObjectCreationAsStatement
             new DateTime(int.Parse(dateStrings[2]), int.Parse(dateStrings[1]), int.Parse(dateStrings[0]));
             inputParam.Result = true;
             inputParam.MsgError = "Không lỗi";
         }
         catch (Exception)
         {
             inputParam.Result = false;
             inputParam.MsgError = "Ngày này không tồn tại";
         }
         //inputParam.Result = true;
         //inputParam.MsgError = "Không lỗi";
     }
     else
     {
         inputParam.Result = false;
         inputParam.MsgError = "Không phải ngày tháng";
     }
     return inputParam;
 }
Example #11
0
 private static InputParam Checkmail(string input)
 {
     var inputparm = new InputParam {InputType = InputType.Email};
     const string pattern = @"^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9]+(\.[a-z]{2,6})?(\.[a-z]{2,6})$";
     if (Regex.IsMatch(input, pattern))
     {
         inputparm.Result = true;
         inputparm.MsgError = "Không lỗi";
     }
     else
     {
         inputparm.Result = false;
         inputparm.MsgError = "Không đúng định dạng Email";
     }
     return inputparm;
 }
Example #12
0
 /// <summary>
 /// truyền vào 1 kiểu inputparam
 /// </summary>
 /// <returns>trả về 1 kiểu InputParam đã được check Error và Result</returns>
 public static InputParam ValDataOne(InputParam inputparam)
 {
     InputParam inputValue;
     if (inputparam.InputType == InputType.KhongKiemTra)
     {
         inputValue = inputparam;
         return inputValue;
     }
     if (string.IsNullOrEmpty(inputparam.Input))
     {
         inputparam.Result = false;
         inputparam.MsgError = "Không được để trống.";
         inputValue = inputparam;
     }
     else
     {
         switch (inputparam.InputType)
         {
             case InputType.SoNguyen:
             {
                 inputValue = CheckSoNguyen(inputparam.Input);
             }
                 break;
             case InputType.SoNguyenDuong:
             {
                 inputValue = CheckSoNguyenDuong(inputparam.Input);
             }
                 break;
             case InputType.SoThucDuong:
             {
                 inputValue = CheckSoThucKhongAm(inputparam.Input);
                 break;
             }
             case InputType.SoThuc:
             {
                 inputValue = CheckSoThuc(inputparam.Input);
                 break;
             }
             case InputType.NgayThang:
             {
                 inputValue = CheckNgayThang(inputparam.Input);
                 break;
             }
             case InputType.Email:
             {
                 inputValue = Checkmail(inputparam.Input);
                 break;
             }
             default:
             {
                 inputValue = inputparam;
                 break;
             }
         }
     }
     return inputValue;
 }
Example #13
0
        /// <summary>
        /// truyền vào 1 kiểu inputparam
        /// </summary>
        /// <returns>trả về 1 kiểu InputParam đã được check Error và Result</returns>
        public static InputParam ValDataOne(InputParam inputparam)
        {
            InputParam inputValue;

            if (inputparam.InputType == InputType.KhongKiemTra)
            {
                inputValue = inputparam;
                return(inputValue);
            }
            if (string.IsNullOrEmpty(inputparam.Input))
            {
                inputparam.Result   = false;
                inputparam.MsgError = "Không được để trống.";
                inputValue          = inputparam;
            }
            else
            {
                switch (inputparam.InputType)
                {
                case InputType.SoNguyen:
                {
                    inputValue = CheckSoNguyen(inputparam.Input);
                }
                break;

                case InputType.SoNguyenDuong:
                {
                    inputValue = CheckSoNguyenDuong(inputparam.Input);
                }
                break;

                case InputType.SoThucDuong:
                {
                    inputValue = CheckSoThucKhongAm(inputparam.Input);
                    break;
                }

                case InputType.SoThuc:
                {
                    inputValue = CheckSoThuc(inputparam.Input);
                    break;
                }

                case InputType.NgayThang:
                {
                    inputValue = CheckNgayThang(inputparam.Input);
                    break;
                }

                case InputType.Email:
                {
                    inputValue = Checkmail(inputparam.Input);
                    break;
                }

                default:
                {
                    inputValue = inputparam;
                    break;
                }
                }
            }
            return(inputValue);
        }