javascript - Text box entered date should be in dd/MM/yyyy while creating date object using Jscript -


enter code heresuggest 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

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -