substring javascript and html -
<script> function myfunction(){ //example passed in 31-02-2013 //var timedate = document.getelementbyid('date').text; <--this wont work! //this basic example only. badly formatted user entry cause //sorts of problems. var timedate = document.getelementbyid('date').value; //get first 2 characters var first2 = timedate.substring(0,2); console.log(first2); var datearray = timedate.split("-"); console.log(datearray[0]); var date = parseint(datearray[0], 10) ;//make sure use radix otherwise leading 0 hurt console.log(date); if( date < 1 || date > 30 ) alert( "invalid date" ); var month2 = timedate.substring(3,5); console.log( month2 ); var montharray = timedate.split( "-" ); console.log( montharray[1] ); var month = parseint( montharray[1],10 ); console.log( month ); if( month < 1 || month > 12 ) alert( "invalid month" ); } </script>
my function working, want correction if user input -23-11-2013 // <--this won't work first alphabet "-"
my text input accept date 23-11-2013 // <---will work.
but function if insert date -23-11-2013 show invalid month . should changes function
check javascript substring function here
my example : results in est
var ="test"; console.log(a.substring(1));
Comments
Post a Comment