Skip to content

Instantly share code, notes, and snippets.

View ericwwsun's full-sized avatar

Eric Sun ericwwsun

  • IBM iX
  • New York City
View GitHub Profile
@ericwwsun
ericwwsun / gist:2113675
Created March 19, 2012 14:12
Javascript: jQuery start template
//validation functions
function validateEmail(email){
var filter = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/
if(filter.test(email)){
return tru
@ericwwsun
ericwwsun / gist:2149064
Created March 21, 2012 16:07
Javascript: Validate Email
//validation functions
function validateEmail(email){
var filter = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/
if(filter.test(email)){
return tru
@ericwwsun
ericwwsun / html5_template.html
Created March 21, 2012 18:37 — forked from nathansmith/html5_template.html
HTML: Simple HTML5 Template
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>PAGE TITLE</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="css/normalize.css" rel="stylesheet" media="all">
<link href="css/styles.css" rel="stylesheet" media="all">
</head>
@ericwwsun
ericwwsun / index.html
Created March 21, 2012 18:38 — forked from m4n/index.html
HTML5 template
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.js"></script>
<script type="text/javascript">
</script>
<style text="text/css">
@ericwwsun
ericwwsun / gist:2891905
Created June 7, 2012 22:05
Javascript: Placeholder in IE
// Form - Placeholder
if(!Modernizr.input.placeholder) {
//alert("no placeholder!!!!!");
$j("*:text:not([type='password'])").each(function(){
//$j(this).css("border","solid 1px red");
if( $j(this).attr("placeholder") && $j(this).attr("placeholder").length > 1 ) {
var placeholderTxt = $j(this).attr("placeholder");
$j(this).val(placeholderTxt);
@ericwwsun
ericwwsun / gist:2950681
Created June 18, 2012 21:03
Javascript: Key/Value Array Example
var dropdowns = {
className1: 'classname1',
className2: 'classname2',
className3: 'classname3'
};
for(index in dropdowns) {
if( dropdowns[index] != currentClass) {
$j('.' + dropdowns[index]).dosomething();
}
@ericwwsun
ericwwsun / namespace.html
Created June 21, 2012 03:06
Javascript: Namespace Revealing Module Pattern
Namespace
@ericwwsun
ericwwsun / gist:2998826
Created June 26, 2012 20:42
Javascript: iPad Orientation and scale, ref: http://adactio.com/journal/4470/
// iPad Orientation and scale , ref: http://adactio.com/journal/4470/
if (navigator.userAgent.match(/iPhone/i) || navigator.userAgent.match(/iPad/i)) {
var viewportmeta = document.querySelector('meta[name="viewport"]');
if (viewportmeta) {
viewportmeta.content = 'width=device-width, minimum-scale=1.0, maximum-scale=1.0, initial-scale=1.0';
document.body.addEventListener('gesturestart', function () {
viewportmeta.content = 'width=device-width, minimum-scale=0.25, maximum-scale=1.6';
}, false);
}
}
@ericwwsun
ericwwsun / gist:2998840
Created June 26, 2012 20:43
Javascript: Cookies
setCookie: function(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
},
@ericwwsun
ericwwsun / gist:2998847
Created June 26, 2012 20:45
Javascript: if is Mobile detection
isMobile: function() {
// detect user agent
var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
var result = false;
if (mobile) {
result = true;
var userAgent = navigator.userAgent.toLowerCase();
if ((userAgent.search("android") > -1) && (userAgent.search("mobile") > -1))
result = true; // android mobile