Click here to Skip to main content
15,889,723 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
var chkdate = document.getElementById("<%=txtFromDate.ClientID %>").value
if (document.getElementById("<%=txtFromDate.ClientID %>").value == "") {
alert("Please enter the Date..!!")
hh.date_slot.focus();
return false;
}
else if (!chkdate.match(/^(0[1-9]|1[012])[\-\/.](?:(0[1-9]|[12][0-9]|3[01])[\- \/.](19|20)[0-9]{2})$/)) {
alert('date format is wrong');
hh.date_slot.focus();
return false;
}

The above function is validating MM/dd/yyyy format..

I need to validate with time also.. MM/dd/yyyy hh:mm:ss format...
Where i want to make the change..??\

Please help me.

Thanks
Posted
Updated 28-Oct-13 0:11am
v8

I'm guessing that you got this function from somewhere else?
The reason I say that, is because if you wrote it yourself, or even stopped and studied the code you would be able to identify what you need to change without the need to post on here.

I suggest you look at this line of code here:

JavaScript
(!chkdate.match(/^(0[1-9]|[12][0-9]|3[01])[\- \/.](?:(0[1-9]|1[012])[\-\/.](19|20)[0-9]{2})$/))

As this is the line that is doing the current comparison, all you need to do is move the "month" section to where the "day" section is and vice versa.
 
Share this answer
 
Comments
kanamala subin 28-Oct-13 4:53am    
can you please give me the edited code...For me its getting error..
Pheonyx 28-Oct-13 5:01am    
What error are you getting?
var chkFromdate = document.getElementById(<%=txtFromDate.ClientID %>;).value
var chkTodate = document.getElementById(<%=txtToDate.ClientID %>).value



if (!chkFromdate.match(/^(0[1-9]|1[012])[\/.](?:(0[1-9]|[12][0-9]|3[01])[\/.](19|20)[0-9]{2}\s[0-1][0-9]:[0-5][0-9]:[0-5][0-9]$/))
alert('date format is wrong');
document.getElementById("<%=txtFromDate.ClientID %>").focus();
return false;
}



if u want to validate AM and PM also


use expression as

chkFromdate.match(/^(0[1-9]|1[012])[\/.](?:(0[1-9]|[12][0-9]|3[01])[\/.](19|20)[0-9]{2}\s[0-1][0-9]:[0-5][0-9]:[0-5][0-9]\s(a|p|A|P)(m|M))$/))
 
Share this answer
 

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