Avatar of Whing Dela Cruz
Whing Dela Cruz
Flag for Anguilla

asked on 

Boolean

Hi experts, I wish to use Boolean to check whether true or false. The code below is not working, Any help please!

<!Doctype Html>
<Html>
<Body>
<input type="text" id="bday"/>
<button onclick="ValiDate()">Validate</button>

<script>
function ValiDate()
{
  if (ValiBday == true)
  {
    alert("true");
  }
  else
  {
    alert("false");
  }
}


function ValiBday()
{
//I get the value of the input element
  var inputValue=document.getElementById('bday').value;
// I create a new var with Regex rule to get only numbers
  var pattern =/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/;
//I set a flag boolen to test if the inputValue has RegEx format
  var flag=pattern.test(inputValue);
//I create an if condition to check if flag is true or false
  if(flag===false){
    ValiBday = "false";
    return false;
  }  
  //I parse the value to date object time in unix format (ms)
  var birthday =Date.parse(document.getElementById('bday').value); 
  //I check the condition  
   if(isNaN(birthday))
    {
        ValiBday = "false";
        return false;
    } 
        ValiBday = "true";
}
</script>

</Body>
</Html>

Open in new window

ASPHTMLJavaScript

Avatar of undefined
Last Comment
Michel Plungjan

8/22/2022 - Mon