function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
test269test269 

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}$/ ;

if(trans!=''){

if(!validformat.test(trans)){
condition=1;

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 

Navatar_DbSupNavatar_DbSup

Hi,

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.")

else

returnval=true

}

}

 

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

test269test269

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.