+ Start a Discussion

date validation in vf page.

Hi all,

   i have written the following code for date format validation in vf page.


var trans=jQuery.trim(jQuery(".transaction").val());

var validformat=/^\d{1,2}\/\d{1,2}\/\d{4}$/ ;

var validformat=/^\d{1,2}\/\d{1,2}\/\d{4}$/ ;



alert('date must be in valid format');



it wrks fine .But i enter the value(13/16/2012-mm/dd/yy) not showing error msg.But i want to display the error msg as its invalid date.Any one can you please help me this.


Thanks in advance 



Try the below javascript function as reference:


function checkdate(input){

var validformat=/^\d{2}\/\d{2}\/\d{4}$/ //Basic check for format validity

var returnval=false

if (!validformat.test(input.value))

alert("Invalid Date Format. Please correct and submit again.")

else{ //Detailed check for valid date ranges

var monthfield=input.value.split("/")[0]

var dayfield=input.value.split("/")[1]

var yearfield=input.value.split("/")[2]

var dayobj = new Date(yearfield, monthfield-1, dayfield)

if ((dayobj.getMonth()+1!=monthfield)||(dayobj.getDate()!=dayfield)||(dayobj.getFullYear()!=yearfield))

alert("Invalid Day, Month, or Year range detected. Please correct and submit again.")






Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 


Hi thanks for ur help,


   But i m not getting how to call that function in to <apex:inputtext value="{!enddate}" styleclass="ed"/> this text field.


Any one can u please help me this .



Thanks in advance.