verN Posted April 6, 2007 Share Posted April 6, 2007 hi, i have a text box where the user enters the date however, iwould like to validate the user's input by checking that the user have (1) inputted the date in the following format DD/MM/YY (2) and words are not entered e.g dkfgsdjg (3) the day, month, year are correct e.g don't allow 32/14/2006 $date = $_POST['dates']; how could i do this, i'm thinking of using javascript but do not know how to go about solving this probelm. I would like a message outputted telling the user the date they entered e.g. 25/44/2007 was incorrect and they should input a date in the cprrrect format e.g. DD/MM/YYYY. thanks Quote Link to comment Share on other sites More sharing options...
desithugg Posted April 6, 2007 Share Posted April 6, 2007 <head> <script language='javascript'> function validiate(myform) { if(!myform) { myform="frm"; } day = document.forms[myform].dd.value; month = document.forms[myform].mm.value; year = document.forms[myform].yy.value; checklength('day',day,2); checklength('month',month,2); checklength('year',year,2); checktype('day',day); checktype('month',month); checktype('year',year); } function checklength(field,val,len) { thesize = val.length; if(thesize > len){ alert('The '+field+' field is too long it must be no longer than '+len+' characters.');} } function checktype(field,val) { if (isNaN(val)){ alert('The field '+field+' is invalid, Only numbers allowed.');} } </script> </head> <body> <form name='frm'> <input size='2' name='dd' maxlength='2' value='dd'> <input size='2' name='mm' maxlength='2' value='mm'> <input size='2' name='yy' maxlength='2' value='yy'> <input type='button' onclick='validiate(frm);'> </form> </body> A little bit of google search won't hurt lol. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.