.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Problem with date validation.

Posted By:      Posted Date: September 23, 2010    Points: 0   Category :ASP.Net

I have the following code:

protected bool ValidGebdat()
    Regex LongDate = new Regex("^([1-9]|0[1-9]|1[012])[- /.]([1-9]|0[1-9]|[12][0-                   9]|3[01])[- /.][0-9]{4}$");

    string gebDat = GebdatTB.Text;

    string s = gebDat.Trim();

            if (LongDate.Match(s).Success)
                   return true;
                  return false;

Why do I get a return false when I insert "27-02-1970"?

View Complete Post

More Related Resource Links

Date validation problem modelstate.isvalid is false

In my view i am formatting the date as follows<%= Html.TextBox("MemoDate", string.Format("{0:dd/MM/yyyy hh:mm}", DateTime.Now),new{ @readonly = true })%> In controller ModelState.IsValid become false as my current culture culture {en-US} doesn't match with the format of date.

Problem with future date validation using CompareValidator


Realy simple aspx page:

<asp:TextBox ID="txtExpireDate" runat="server" Width="78px" MaxLength="10" ></asp:TextBox>


SSRS 2008 date validation

Hello, Perhaps somone can shed some light on this. I want to make sure the user doesn't set a Startdate > EndDate  in a report. I've done some thing like this: Go to the Report Properties under the Report menu and place this code to the Code Tab. Public Function CheckDate(SDate as Date, EDate as Date) as Integer Dim msg as String msg = "" If (SDate > EDate) Then msg="Start Date should not be later than End Date" End If If msg <> "" Then MsgBox(msg, 16, "Parameter Validation Error") Err.Raise(6,Report) 'Raise an overflow End If End Function Then go to the Report Parameters and Add named it XXX with the datatype is string. Checked the Hidden and Allow blank value ckeckboxes. In Available Values choose Non-Queried and from Default Values choose Non-Queried in right side of textbox then press the FX button then paste this code. =CODE.CheckDate( .Value) But I'm having problems with the =CODE.CheckDate( .Value)  syntax. SSRS errors out. Any suggestions/insights? --joe

DataContractJsonSerializer: Problem when deserializing the Date

Sorry for cross-posting. I posted the same question on the Silverlight forum, but it has not received a single answer yet. The majority of folks there must be more interested in UI than in more fundamental stuff.     Hello everyone! Let's say we have the folllowing POCO classes: public class PocoObject : List<PocoPropertyData> {     public PocoObject() {}     public override string ToString()     {         var parts = new List<string>();         foreach (var pd in this)             parts.Add(string.Format("{{N=[{0}], Type=[{1}], V=[{2}]}}", pd.N, pd.V == null ? typeof(object) : pd.V.GetType(),  pd.V));         return string.Join(",", parts);     } } public class PocoPropertyData {     public string N { get; set; }  // the property name     public object V { get; set; }  // the property value } As you can see, the PocoPropertyData can hold value of any type. When I execute the following code in both .NET 4 application and Silverlight 4 application: ========================================================= var poco = new PocoObject {       { new PocoPropertyData { N = "DateTimeField", V =  Da

validation problem

hii design a register users form for my wesite.i using validation controls in my form, for instance(requiredfield validator and compare validator)i make validation group for my validation controls and register buttonvalidation group is equal for all my validation controls and button. when is empty one of textboxes and i click on register button first run button function then enable validationsthis is my problemthe validations must enable before run the button functionthis is my html codes:<table class="format">                                <tr>                                    <td colspan="2">                                        <asp:Label ID="Label10" runat="server" Font-Bold="True" Font-Names="Tahoma"             &n

Problem casting date

I'm developing a Windows Forms app using VS 2008 with a SQL Server 2005 database. I've got search form where users can search for data by entering one or two criteria. One of these is a date which corresponds to a date field in my database. The user clicks on a button, which feeds the criteria into a stored procedure. The results are displayed in a datagridview control. While the functionality works well with the non-date criteria, whenever a date criteria is used on it's own a cast error is raised ('Conversion failed when converting datetime from character string.') I've tried lots of ways of casting the date (formatting using left, right and mid finctions, using the substring function etc) but still can't get it to work. Code and SQL are shown below. Does someone know where I've gone wrong? 'DateAssayRequested' is the date in question. <vb> 'set up and initialise connection conn = New SqlConnection(etc) comm = New SqlCommand comm.Connection = conn comm.CommandText = "SPSearch" comm.CommandType = CommandType.StoredProcedure 'create input parameters, set types and values param = comm.CreateParameter param.ParameterName = "@assayid" param.Direction = ParameterDirection.Input param.Value = txtLabNo.Text

Problem with date values in data-driven subscription reports

Hello together, I have a question in regards of data-driven subscription report. I already have an ad-hoc report in place which can be customized by date etc. I now want to run these reports with a subscription. My challenge is now that I don't know how I can pre-define the date. I basically want the start date of NOW() and the end date 7 days in the past. I was looking around but did not get any clue where and how I have to configure it the way it works. I found this thread but honestly do not understand it well... :( http://social.msdn.microsoft.com/Forums/en-US/sqlreportingservices/thread/fb48fd15-09dd-4f5f-a09f-d92bf304c1a2 Can someone help me out please? M.

SSRS 2008 R2 Problem understanding View State Validation steps

Hi, Sorry, but I have some problem understanding this steps. Please help me to understand this.  Pasted from http://technet.microsoft.com/en-us/library/cc281307.aspx?lc=1033 How to Configure View State Validation To run a scale-out deployment on an NLB cluster, you must configure view state validation so that users can view interactive HTML reports. You must do this for the report server and for Report Manager. View state validation is controlled by the ASP.NET. By default, view state validation is enabled and uses the identity of the Web service to perform the validation. However, in an NLB cluster scenario, there are multiple service instances and web service identities that run on different computers. Because the service identity varies for each node, you cannot rely on a single process identity to perform the validation. To work around this issue, you can generate an arbitrary validation key to support view state validation, and then manually configure each report server node to use the same key. You can use any randomly generated hexadecimal sequence. The validation algorithm (such as SHA1) determines how long the hexadecimal sequence must be. Generate a validation key and decryption key by using the autogenerate functionality provided by the .NET Framework. (Well, how to generate Validation key using .Net Framework?) In the end, you must have a singl

validation problem

hii design a user register form for my website.in this form i using validation control.for instance : required field validator and compare validator.but i have problem with this controlsi make a Validationgroup for validation with register button.validationgroup is equal for all controls(validations and button).when i dont fill textboxes and i click on the button first run the button function then run validations.where is my problem?this is my html codes:<table class="format">                                <tr>                                    <td colspan="2">                                        <asp:Label ID="Label10" runat="server" Font-Bold="True" Font-Names="Tahoma"                   &

Javascript FromDate to Date Validation Help!

Hi,I want to check fromdate and todate in dd/mm/yyyy.The code below mentioned works perfect for single textbox(fromdate) ,but when tried to do for todate(textbox) it doesnot work properly.From Date Should not be greater than ToDate.Please Help.Below is the code:<html><head><title>Date Example</title><script type="text/javascript">    function isValidDate(sText) {        var reDate = /(?:0[1-9]|[12][0-9]|3[01])\/(?:0[1-9]|1[0-2])\/(?:19|20\d{2})/;        return reDate.test(sText);    }    function validate() {        var oInput1 = document.getElementById("txt1");        if (isValidDate(oInput1.value)) {            alert("Valid");        } else {            alert("Invalid!");        }    }</script></head><body>    <P>Date: <input type="

Date Validation and Date Formatting

 Hi,   I am new to ASP.NET 4.0 and the whole Object Oriented Programming.  I added a Calendar Extender on a text box.  Now I would like it to be formatted to MM/DD/YY, PLUS, I also want to validate if the date entered is more than let's say 90 days from today.  If it is more than 90 days, I would like to show something like an error message and set the focus on the date field.  I am writting my code in C#.  Can any body help on this?  Thank you. esant    

Problem displaying Date from Sql table on Calendar Control

Hi, I am displaying Event dates from SQL table on Calendar Control in ASP.NET. Also, I have GridView Control which shows event details when certain date is clicked on calendar control. But I have a problem as not all dates are displaying properly. Strangly enough only dates which have same month and day date are displayed. For example: It shows ok dates such as 08/08/2010, 09/09/2010, 10/10/2010 etc. If I click on the date which in SQL table exists as 11/25/2010 or 12/15/2010 etc (no matching month/day numbers) it shows error message saying: "System.Data.SqlClient.SqlException: Conversion failed when converting date and/or time from character string."  Follwoing is my code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.Sql; using System.Runtime.Remoting.Messaging; using System.Configuration; using System.Data.SqlClient; using System.Data; using System.Drawing; public partial class Test_Calendar : System.Web.UI.Page { SqlConnection mycn; SqlDataAdapter myda; DataSet ds = new DataSet(); DataSet dsSelDate; String strConn; private void Page_Load(object sender, System.EventArgs e) { strConn = "Data Source=mydatasource;Initial Catalog=DBname;Persist Security I

Date formate problem

Hi I have faced one problem with processing date field from xml file. i have read RSS site and get date field from this site and parse that date field using below code i got pubDate field from xml like : <pubDate >06 Sept 2010 09:15:01 +0300</pubDate > datefield = DateTime.Parse(xmlfile.Element("pubDate").Value.Replace("\n\r", "").Replace("\r\n", "").Replace("\n", "").Replace(" Sept "," Sep ").Trim(), FinishCulture.DateTimeFormat, DateTimeStyles.AdjustToUniversal).AddHours(3).ToString("dd.MM.yyyy HH:mm:ss"),   I have face this problem because of month format "Sept". i have also implement this functionality with other RSS site they working fine with above code as they return date like : <pubDate >06 Sep 2010 09:15:01 +0300</pubDate > So, the problem is with month name Sept - Sep. can you please tell me how can i handle "Sept" month name format.   Thanks Nikunj Padaliya  

Date Time interval Problem

Hi I have a problem in which i have to check the time interval to the another which is already exist in Database table.For Exp.10:00 am  To 11:00 am i add an Event now if user insert the again this time interval  it's throw the error message.if user want's to edit this event For exp.10:15 am to 11:00 amhow do this.Thanks

StrToMember problem with todays date.

Hi, I want a calculated member who will give me the bookvalues for todays month. When i run these two scripts (variables and hardcoded examples) in SQL server management studio the result are shown for both scripts no problem there: SELECT {[Measures].[Asset Bookvalue balance]} ON 0,  [MSN].[Asset].[Asset] on 1 from CMSX_DWH_OLAP  where {StrToMember("[Book Value Start Date].[Year - Quarter - Month].[Month].&["  + Format(now(), "yyyy") + "]&[" +  Format(now(), "MM") + "]")}       SELECT {[Measures].[Asset Bookvalue balance]} ON 0, [MSN].[Asset].[Asset] on 1 from CMSX_DWH_OLAP  where [Book Value Start Date].[Year - Quarter - Month].[Month].&[2010]&[09]   next step is to change the two scripts in order to be used as a Calculated Member: CREATE MEMBER CURRENTCUBE.[Measures].[Todate Asset Bookvalue balance]  AS ([Measures].[Asset Bookvalue balance],{StrToMember("[Book Value Start Date].[Year - Quarter - Month].[Month].&["  + Format(now(), "yyyy") + "]&[" +  Format(now(), "MM") + "]")}),  FORMAT_STRING = "#,#.00;(#,#.00)",  VISIBLE = 1  ;       CREATE MEMBER CURRENTCUBE.[Measures].[Todate Asset Bookvalue balance2]  AS ([Measur

Date Range Problem

How would I go about returning the closest ReleaseDate to DateIn? The record I would like to return is (2010-07-18 00:00:00.000 2010-07-17 00:00:00.000) CREATE TABLE #test ( ID INT ,DateIn DATETIME ,ReleaseDate DATETIME ) INSERT INTO #test VALUES(1, '07/18/2010', '01/10/2010') INSERT INTO #test VALUES(2, '07/18/2010', '07/17/2010') SELECT * FROM #test WHERE CONVERT(CHAR(10), '07/17/2010', 101) <= CONVERT(CHAR(10), '07/18/2010', 101) AND CONVERT(CHAR(10), '07/18/2010', 101) <= CONVERT(CHAR(10), '01/10/2010', 101) DROP TABLE #test  

problem in date format in sql 2005

I am new to sql2005  My problem is,  I send a date parameter (@fdt  and @Tdt)   like "DD/MM/YYYY" format through Sql reporting services My query is select  * from deposits where Depdate >= @fdt and Depdate <=  @tdt in the aove query there is no record has been fetched   But i give like this,  Inthis case i get a resultselect  * from deposits where Depdate >= '2010/04/01' and Depdate <= '2010/08/31' pls tell me how can i convert the date to "yyyy/mm/dd"    in where condition   Thanks Gk  
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend