Skip to content

Instantly share code, notes, and snippets.

View dnntung's full-sized avatar
🎧
Listening music

doodleragon dnntung

🎧
Listening music
  • MB
  • A fantasy world in Vietnam
  • 19:23 (UTC +07:00)
View GitHub Profile
/**
* Takes a string and returns true if its a valid email address.
* @param {String} email Email address to be tested for validity.
* @return {Boolean} True if valid email, false if not.
*/
function isValidEmail(email) {
var regex = /^([a-zA-Z0-9_.+-])+\@(([a-zA-Z0-9-])+\.)+([a-zA-Z0-9]{2,4})+$/;
return regex.test(email);
}
@lanqy
lanqy / bytesToSize.js
Created March 19, 2013 03:05
JavaScript To Convert Bytes To MB, KB, Etc
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};