troubleshooting Question

Boolean

Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla asked on
ASPHTMLJavaScript
13 Comments4 Solutions243 ViewsLast Modified:
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

ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 4 Answers and 13 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 4 Answers and 13 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros