Web Programming Training By OM SIR Call for free Demo :9320957717/18

date-month-year validation in javascript

<script>
function check()
{

   var dateCheck = /^(0?[1-9]|[12][0-9]|3[01])$/;
   var monthCheck = /^(0[1-9]|1[0-2])$/;
   var yearCheck = /^\d{4}$/;
    var  a =document.myform.date.value;
var  b=document.myform.month.value;
var c=document.myform.year.value;
if(a.match(dateCheck))
  {
    alert ("date is ok");
  }
 
  else
  {
  alert ("date is not ok");
  }
 
  if(b.match(monthCheck))
  {
    alert ("month is  ok");
  }
 
  else
  {
  alert ("month is not ok");
  }
 
  if(c.match(yearCheck))
  {
    alert ("year is  ok");
  }
 
  else
  {
  alert ("year is not ok");
  }
}
</script >

<form name=myform>
Enter Date:<input type=text name=date>
Enter Month:<input type=text name=month>
Enter year<input type=text name=year>

<INPUT name="Submit"  type="button" class="style2" onclick="javascript:check();" value="Submit">
</form>
Previous
Next Post »

1 comments:

Write comments
Garima Ahuja
AUTHOR
23 October 2017 at 02:35 delete

informative blog for fresher
i must say if fresher can follow your blog so he she don't need to join any course or other institute they can learn java script from your blog
https://sisgain.com/hire-android-developer

Reply
avatar