Wednesday, February 3, 2010

Server Validation for Time HH:MM M/PM format


case "time":
 {
                            //Regex regExpression = new Regex(@"^(\d{2}):(\d{2})\s{1}(([aA])|([pP]))[mM]$");
                            //new Regex(@"^(\d{2}):(\d{2})\s{1}([AP]M)$");
                            // ^(([1-9]{1})|([0-1][1-2])|(0[1-9])|([1][0-2])):([0-5][0-9])(([aA])|([pP]))[mM]$
                            Regex regExpression = new Regex(@"^(([1-9]{1})|([0-1][1-2])|(0[1-9])|([1][0-2])):([0-5][0-9])\s{1}(([aA])|([pP]))[mM]$");
                            if (drValidation["value"].ToString().Trim().Length > 0)
                                if(!regExpression.IsMatch(drValidation["value"].ToString().Trim()))
                                {
                                    strError.Append("");
                                    blnReturnVal = false;
                                }
                            break;
                        }

No comments:

Post a Comment