neo
neo

Reputation: 177

javascript not running onBlur

The function to validate the date field is not executing onBlur below. I'm not sure what I'm missing here. Just trying to test a simply validation.

   <div class="cell">
   <label>DOB</label><br>       
   <input id="dob" type="text" placeholder="01/01/1980" onBlur="checkForm(this.value);">
   </div>


   <script type="text/javascript">


 function checkForm(form)
 {
// regular expression to match required date format
re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;

if(form.dob.value != '' && !form.dob.value.match(re)) {
  alert("Invalid date format: " + form.dob.value);
  form.dob.focus();
  return false;
}



alert("All input fields have been validated!");
return true;
 }

Upvotes: 0

Views: 26

Answers (1)

LearningEnthu
LearningEnthu

Reputation: 24

 <div class="cell">
   <label>DOB</label><br>       
   <input id="startdate" type="text" placeholder="01/01/1980" onblur="checkForm()">
   <script>
    function checkForm()
 {
// regular expression to match required date format
re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
var date = document.getElementById("startdate").value;
alert(date);
if(date != '' && !date.match(re)) {
  alert("Invalid date format: " + date);
  date.focus();
  return false;
}
alert("All input fields have been validated!");
return true;
 }
   </script>
   </div>

Upvotes: 1

Related Questions