Automatic Time Formatting And Validation Plugin - jQuery Slim Time

File Size: 110 KB
Views Total: 65
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   
Automatic Time Formatting And Validation Plugin - jQuery Slim Time

Slim Time is a tiny but powerful jQuery plugin that simplifies the process of formatting and validating time strings in your text field. With this jQuery plugin, you can automatically ensure that the time entered by your users is in the correct format.

Some examples:

  • 6:25 => 6:25am
  • 625 => 06:25 (24-hour enabled)
  • 18:25 => 6:25pm
  • 6 => 6:00am
  • 625 => 6:25am
  • 6:25pm => 6:25:00pm (seconds enabled)
  • 6:25:25pm => 6:25pm (seconds disabled)

How to use it:

1. Download the plugin and load the jquery.slim_time.min.js after jQuery.

<script src="/path/to/cdn/jquery.slim.min.js"></script>
<script src="/path/to/jquery.slim_time.min.js"></script>

2. Call the function on your text field and the plugin will do the rest.

<input type="text" name="time" id="time" />
$(function(){
  $('#time').slimTime();
});

3. Change time format to 24 hours.

$(function(){
  $('#time').slimTime({
    "default": 24
  });
});

4. Determine whether to include seconds. Default: false.

$(function(){
  $('#time').slimTime({
    "seconds": true
  });
});

5. Show a visual error feedback when the text field is empty.

$(function(){
  $('#time').slimTime({
    "required": true
  });
});
.slim-time-error {
  /* your styles here */
}

This awesome jQuery plugin is developed by aklump. For more Advanced Usages, please check the demo page or visit the official website.