Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <p>
    <label>Start:</label><input type="text" class="start" placeholder="HH:MM AM/PM">
    <span class="error"></span>
  </p>
  <p>
    <label>End:</label><input type="text" class="end" placeholder="HH:MM AM/PM">
    <span class="error"></span>
  </p>
  <button>Submit</button>
</body>
</html>
 
function isTime(str) {
  return /^([1-9]|1[012]):[0-5][0-9]\s*?(am|pm)$/i.test(str);
}
$('button').click(function(e){
  e.preventDefault();
  
  var start = $.trim($('.start').val())
    , end = $.trim($('.end').val());
  
  console.log(start, end);
  
  $('.error').hide();
  
  if (!isTime(start)) {
    $('.start ~ .error').show().html('Please enter a valid time.');
  }
  
  if (!isTime(end)) {
    $('.end ~ .error').show().html('Please enter a valid time.');
  }
});
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
elclanrspro
0viewers