.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

Javascript FromDate to Date Validation Help!

Posted By:      Posted Date: September 04, 2010    Points: 0   Category :ASP.Net
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="

View Complete Post

More Related Resource Links

Javascript Date Validation



I have a few Date validations to perform. I have the following columns "BirthDate","College Review Date", "Project Review Date" created in the custom list. In the Column Date and Time format option, I had choosen "Date Only" format.

I want to do some javascript validations on the date created. For example, BirthDate must be less than or equal to System Date. If the users selects a day greater the System Date, I want to alert the user. The alert should be provided after the date selection has changed, and not on the "OK" button click.

How to achieve this using javascript?

Thank you

decimal value validation and round off by javascript

The article decimal value validation and round off by javascript was added by hiral.hapani on Wednesday, June 02, 2010.

Hi All, I have createdone javascript by which you canvalidate a decimal value of any textbox for which you want. By thisjavascriptwecan bind user to enter only digits in textbox. and when he will enter any decimal value javascript will do round off it

Asp.net Javascript Validation dd/mm/yyyy format


Hi experts,

 I am trying to validate two textbox (fromdate,todate)

should alert a message when Fromdate is more than Todate

I could find only mm/dd/yyyy format in most of google search.

please give me a script or assist how to do this.



How to add days in date using javascript


Hi following is the javascript code which i used for adding days to date

my date is 25/08/2010  and i want to add 8 days to this date  the answer should be 03/09/2010. how it is possible. i tried following code but showing error.



<script type="text/javascript" language="javascript">

function check()
var myDate = new Date();
var vFormat="MM/dd/yyyy";
var vDay                = addZero(myDate.getDate()); 
var vMonth            = addZero(myDate.getMonth()+1); 
var vYearLong         = addZero(myDate.getFullYear()); 
var vYearShort        = addZero(myDate.getFullYear().toString().substring(3,4)); 
var vYear             = (vFormat.indexOf("yyyy")>-1?vYearLong:vYearShort) 
var vHour             = addZero(myDate.getHours()); 
var vMinute           = addZero(myDate.getMinutes()); 
var vSecond           = addZero(myDate.getSeconds()); 
var myDateString       = vFormat.replace(/dd/g, vDay).replace(/MM/g, vMonth).replace(/y{1,4}/g, vYear) 
myDateString           = myDateString.replace(/hh/g, vHour).replace(/mm/g, vMinute).replace(/ss/g, vSecond) 

function addZero(vNumber){ 
    return ((vNumber < 10) ? "0" : "") + vNumber 


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

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.

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    

javascript for field validation on a textbox...

I'm looking at doing the validation for the email in javascript since we have asp.net 1.1. I can get it to just alert fine, but once I add the return validation it doesn't fire. Me.ImageButton2.Attributes.Add("onclick", "return validation(this);") <script language="JavaScript"> <!-- function validation () { var test=""; test = document.ticketForm.emailAddress.value; if (test == "xyz") { alert(test); return false; // validation failed } --> </script>

radiobutton validation using javascript

hi' i have two radiobuttons and a button.On button click i have to validate whether the radiobutton is selected or not. I tried the following,but it is not working.pls help.<asp:RadioButton  runat="server" ID="rbyes" Text="Yes"  visible="true" GroupName="a"  /> <asp:RadioButton  runat="server" ID="rbno" Text="No" visible="true" GroupName="a" /> <asp:Button  ID="btnOk" runat="server" Text="OK" OnClick="btnOk_Click"  OnClientClick="return selectRadioButton();"/>function selectRadioButton(){var y=document.getElementById("ctl00_ContentPlaceHolder1_rbyes");var n=document.getElementById("ctl00_ContentPlaceHolder1_rbno");if(y.checked==false && n.checked==false){alert(Please select Yes/No");return false;}return true;}

Validation is not working in Custom List Form using JavaScript ddwrt:GenFireServerEvent()

Hii am creating custom New form for a list using sharepoint designer. i have added the below button for sumbit<input name="Submit1" type="submit" value="Submit" onclick="javascript: {ddwrt:GenFireServerEvent('__commit;__redirect={http://myserver/Lists/VTest/AllItems.aspx}')}" />                <xsl:text xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" ddwrt:nbsp-preserve="yes" disable-output-escaping="yes">&amp;nbsp;                                    </xsl:text><input name="Submit2" type="submit" value="Cancel" onclick="javascript: {ddwrt:GenFireServerEvent('__redirect={http://myserver/Lists/VTest/AllItems.aspx}')}" />the problem is the validation is not working properly. it submits the page without entering values for the required fields.particularly the validation is not working for DateFields.let me know what is the problem here. is it a Bug?muthu

Validate (Javascript) if input date is within this range...


I'd like to validate if the inputed date is within this range:

3 weeks before today's date to 3 weeks after today's date 

The following Javascript code checks if the date is within either today's date or 2 weeks before:

var dateSystem = (dateToday.getMonth() + 1) + dtCh + dateToday.getDate() + dtCh + dateToday.getFullYear();
            var prev = new Date();
            //past date 14 dates before today
            prev.setDate(prev.getDate() - 14);
            var pastDate = (prev.getMonth() + 1) + dtCh + (prev.getDate()) + dtCh + prev.getFullYear();
            var time1 = new Date(dateSystem).getTime();
            dtStr = month + dtCh + day + dtCh + year;
            var dateuser = new Date(dtStr);
            var time2 = dateuser.getTime();
            if (time1 - time2 <= 1209600000 && time2 <= time1) {
                return true;
            } else {
                alert("Vaccines/Services date must be within this date range: " + pastDate + " to " + dateSystem);
                return false
            return true


I'm not sure how to modify. I actually got the code above from these forums.

Help is much appreciated!

Problem with date validation.


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"?

Validate ASP.net calendar date selected with Javascript?


Is there any way I can use javascript to make sure the user has selected a date from my asp.net calendar? I have the calendar under an update panel:

                        <asp:UpdatePanel ID="UpdatePanel2" runat="server">
                                <asp:Calendar ID="Calendar1" runat="server" BackColor="#FFFFCC" BorderColor="Maroon"
                                    BorderWidth="1px" CssClass="calendar" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black"
                                    Height="200px" Width="305px" DayNameFormat="Shortest" ShowGridLines="False">
                                    <SelectedDayStyle BackColor="maroon" BorderColor="Black" BorderWidth="1px" Font-Bold="true" Font-Size="11pt" />
                                    <SelectorStyle BackColor="#FFCC66" />
                                    <TodayDayStyle Font-Bold="true" Font-Size="16pt"/>
                                    <OtherMonthDayStyle ForeColor="#CC9966" />

Delaying clientside validation Javascript


For performance reasons, I usually put all my javascripts at the end of my html page.

However, Html.EnableClientValidation() always generates client side validation script after the form in the middle of the document

Is there anything I can do to change this?

What if the MVC team add a DEFER attribute to the generated javascript validation script

so the generated script should like

<script type="text/javascript" defer="defer">
if (!window.mvcClientValidationMetadata) { window.mvcClientValidationMetadata = []; }

validation group creation using javascript


Hi I want to create a validation group using javascript.

How can I do that? 

Javascript Date Range


How can I arrange the javascript to check if the date the user has typed in is within this range? -

2 weeks prior to today and 2 weeks after today

Here's what I have so far:

var prev = new Date();
            var next = new Date();
            //past date 21 day before today
            prev.setDate(prev.getDate() - 21);
            //next date 21 days after today
            next.setDate(next.getDate() + 21);
            var pastDate = (prev.getMonth() + 1) + dtCh + (prev.getDate()) + dtCh + prev.getFullYear();
            var nextDate = (next.getMonth() + 1) + dtCh + (next.getDate()) + dtCh + next.getFullYear();
            var time1 = new Date(dateSystem).getTime();
            dtStr = month + dtCh + day + dtCh + year;
            var dateuser = new Date(dtStr);
            var time2 = dateuser.getTime();
            if (time1 - time2 <= 1209600000 && time2 <= time1) {
                return true;
            } else {
                alert("Vaccines/Services date must be within this date range: " + " " + "\n" + "\n" + "                      " + pastDate + " to " + nextDate);
                return false
            return true


getting time and date from datetime field in javascript


Hello guys, I need to get hours from the difference between two datetime fields. I wrote the javascript which will get the date from datetime field.

But its not getting the correct time that entered on date time field. Its defaultly getting the current time on my system.

So do you guys have any idea. How to get time from date time fields. and how calculate hours between two datetime fields using javascript.

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