Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
i added calender in the form..i need to display error message if user not selecting the date field.
Posted
Comments
hypermellow 16-Sep-14 8:44am    
Can you post your code please?

1 solution

Here is a function to check valid date format as mentioned below :-

JavaScript
function IsValidDate(dtValue)
{
    var dtRegex = new RegExp(/\b\d{1,2}[\/-]\d{1,2}[\/-]\d  {4}\b/);
    return dtRegex.test(dtValue);
}



To Use this method on any date text field below is the code example :-

JavaScript
$(function() {
	$('.errorDiv').hide();
	$('#btnTest').click(function(event){
   		var dtVal=$('#txtDate').val();
   		if(IsValidDate(dtVal))	$('.errorDiv').hide();
   		else
   		{
     			$('.errorDiv').show();
     			event.preventDefault();
   		}
   	});
});


Here 'errorDiv' is the class name assigned to the div used for displaying the error message when date validation fails.

Hope this will be of help to you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900