Skip to content

Instantly share code, notes, and snippets.

@bcoughlan
bcoughlan / humanize.js
Created June 15, 2012 06:08
Javascript - Format seconds to (hh:m)m:ss
function formatTime (t) {
if (typeof (t) !== "number" || t < 0) {
return "";
}
function it(param) {
var p = t % param;
if (p < 10) p = '0' + p;
t = Math.floor(t / param);
return p;
}
@bcoughlan
bcoughlan / validation.js
Created May 9, 2012 21:51
jQuery validation - IP address
//Validation
jQuery.validator.addMethod('validIP', function(value) {
var split = value.split('.');
if (split.length != 4)
return false;
for (var i=0; i<split.length; i++) {
var s = split[i];
if (s.length==0 || isNaN(s) || s<0 || s>255)
return false;