Exemple #1
0
        public void CanValidate()
        {
            RegexStringValidator v = new RegexStringValidator("[0-9]+");

            Assert.True(v.CanValidate(typeof(string)));
            Assert.False(v.CanValidate(typeof(int)));
            Assert.False(v.CanValidate(typeof(object)));
        }
        static void Main(string[] args)
        {
            // Display title.
            Console.WriteLine("ASP.NET Validators");
            Console.WriteLine();

            // Create RegexString and Validator.
            string testString  = "*****@*****.**";
            string regexString =
                @"^[a-zA-Z\.\-_]+@([a-zA-Z\.\-_]+\.)+[a-zA-Z]{2,4}$";
            RegexStringValidator myRegexValidator =
                new RegexStringValidator(regexString);

            // Determine if the object to validate can be validated.
            Console.WriteLine("CanValidate: {0}",
                              myRegexValidator.CanValidate(testString.GetType()));

            try
            {
                // Attempt validation.
                myRegexValidator.Validate(testString);
                Console.WriteLine("Validated.");
            }
            catch (ArgumentException e)
            {
                // Validation failed.
                Console.WriteLine("Error: {0}", e.Message.ToString());
            }

            // Display and wait
            Console.ReadLine();
        }
Exemple #3
0
        public static bool Check_RepID_RegEx(string repID)
        {
            bool   check       = false;
            string regexString =
                @"^[a-zA-Z0-9]+$";
            RegexStringValidator myRegexValidator =
                new RegexStringValidator(regexString);

            // Determine if the object to validate can be validated.
            Debug.WriteLine("CanValidate: {0}",
                            myRegexValidator.CanValidate(repID.GetType()));

            try
            {
                // Attempt validation.
                myRegexValidator.Validate(repID);
                check = true;
            }
            catch (ArgumentException error)
            {
                // Validation failed.
                Debug.WriteLine("Error: {0}", error.Message);
                check = false;
            }
            return(check);
        }
Exemple #4
0
        public static bool Check_ExpirationDate_RegEx(string expirationdate)
        {
            bool   check       = false;
            string regexString =
                @"^(0[1-9]|1[012])[/](0[1-9]|[12][0-9]|3[01])[/](19|20|21)\d\d$";
            RegexStringValidator myRegexValidator =
                new RegexStringValidator(regexString);

            // Determine if the object to validate can be validated.
            Debug.WriteLine("CanValidate: {0}",
                            myRegexValidator.CanValidate(expirationdate.GetType()));

            try
            {
                // Attempt validation.
                myRegexValidator.Validate(expirationdate);
                check = true;
            }
            catch (ArgumentException error)
            {
                // Validation failed.
                Debug.WriteLine("Error: {0}", error.Message);
                check = false;
            }
            return(check);
        }
Exemple #5
0
        public static void Example7()
        {
            //The RegexStringValidator object contains the rules necessary to validate a string object based on a regular expression. The rules are established when an instance of the RegexStringValidator class is created.
            //The CanValidate method determines whether the object type being validated matches the expected type.The object being validated is passed as a parameter of the Validate method.


            // Display title.
            Console.WriteLine("ASP.NET Validators");
            Console.WriteLine();

            // Create RegexString and Validator.
            string testString  = "*****@*****.**";
            string regexString =
                @"^[a-zA-Z\.\-_]+@([a-zA-Z\.\-_]+\.)+[a-zA-Z]{2,4}$";
            RegexStringValidator myRegexValidator =
                new RegexStringValidator(regexString);

            // Determine if the object to validate can be validated.
            Console.WriteLine("CanValidate: {0}",
                              myRegexValidator.CanValidate(testString.GetType()));

            try
            {
                // Attempt validation.
                myRegexValidator.Validate(testString);
                Console.WriteLine("Validated.");
            }
            catch (ArgumentException e)
            {
                // Validation failed.
                Console.WriteLine("Error: {0}", e.Message.ToString());
            }
        }
        public ActionResult Feedbackrecord(Feedbackrecord feedbackrecord)
        {
            Guid            Memberid  = Guid.Parse(Session["Memberid"].ToString());
            Memberblacklist blacklist = new Memberblacklist();
            string          ipaddress;

            ipaddress = Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
            if (ipaddress == "" || ipaddress == null)
            {
                ipaddress = Request.ServerVariables["REMOTE_ADDR"];
            }
            Members Member = membersService.GetByID(Memberid);
            RegexStringValidator myRegexValidator = new RegexStringValidator(@"/^[0 - 9] *$/");

            if (feedbackrecord.Money > Member.Feedbackmoney || feedbackrecord.Money <= 0 || myRegexValidator.CanValidate(feedbackrecord.Money.GetType()))
            {
                blacklist.Account   = Member.Account;
                blacklist.Memberid  = Guid.Parse(Session["Memberid"].ToString());
                blacklist.Useragent = Request.UserAgent;
                blacklist.IP_Addr   = ipaddress;
                memberblacklistService.Create(blacklist);
                memberblacklistService.SaveChanges();
                Session.RemoveAll();
                return(RedirectToAction("Home", "HomeMs"));
            }
            /*** 金額不得小於500 ***/
            if (feedbackrecord.Money < 500)
            {
                return(RedirectToAction("Feedbackrecord"));
            }
            IEnumerable <Feedbackrecord> old_data = feedbackrecordService.Get().Where(a => a.Memberid == Memberid).OrderByDescending(o => o.Createdate);
            int count = old_data.Count();

            if (count == 0)
            {
                Session["Remains"] = Member.Feedbackmoney;
            }
            else
            {
                Session["Remains"] = old_data.FirstOrDefault().Remains;
            }
            Session["Money"] = feedbackrecord.Money;
            return(RedirectToAction("Feedbacktransfer"));
        }