javascript - Text box entered date should be in dd/MM/yyyy while creating date object using Jscript -
enter code here
suggest me on this.. while creating date ref(java script), text box value should treated dd/mm/yyyy format..
function myfunction1(a) { //here input format should dd/mm/yyyy... //but date ref taking mm/dd/yyyy var x=new date(a); alert(x); if(x>new date()) { alert("wrong date"); } else { alert("success"); } } ---- <input name="textbox1" id="textbox1" type="text" /> <input name="buttonexecute" onclick="myfunction1(document.getelementbyid('textbox1').value)" type="button" value="execute" />
try this:
var datestring = document.getelementbyid('<textboxid>').value; var day = parseint(datestring.substring(0,2)); var month = parseint(datestring.substring(3,5)); var year = parseint(datestring.substring(6,10)); alert(new date(year, month - 1, day));
to validate date, use code:
alert(/^(0[1-9]|[12][0-9]|3[01]|[1-9])[- /.](0[1-9]|1[012]|[1-9])[- /.](\d{4})$/.test(datestring));
it return true if date valid else return false.
Comments
Post a Comment