Advertisement
badlogic

time validation inp

Aug 16th, 2017
341
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <p>This demo used to validate time with 12 hours format</p>
  6.  
  7. <button onclick="myFunction()">Try it</button>
  8.  
  9. <p id="demo"></p>
  10.  
  11. <script>
  12. function myFunction() {
  13. var regexp = /^(0?[1-9]|1[012])(:[0-5]\d) [APap][mM]$/;
  14. var res = regexp.test('12:00 AM'); //try with alphabets or wrong format
  15. document.getElementById("demo").innerHTML = res;
  16. }
  17. </script>
  18.  
  19. </body>
  20. </html>
  21.  
  22.  
  23.  
  24.  
  25. $time_in_12_hour_format = date("g:i a", strtotime("13:30"));
  26.  
  27. // 12-hour time to 24-hour time
  28. $time_in_24_hour_format = date("H:i", strtotime("1:30 PM"));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement