Skip to content

Instantly share code, notes, and snippets.

View zhuochun's full-sized avatar

Zhuochun zhuochun

View GitHub Profile
@zhuochun
zhuochun / example-user.js
Created June 14, 2012 14:53 — forked from nijikokun/example-user.js
Beautiful Validation... Why have I never thought of this before?!
var user = {
validateCredentials: function (username, password) {
return (
(!(username += '') || username === '') ? { error: "No Username Given.", field: 'name' }
: (!(username += '') || password === '') ? { error: "No Password Given.", field: 'pass' }
: (username.length < 3) ? { error: "Username is less than 3 Characters.", field: 'name' }
: (password.length < 4) ? { error: "Password is less than 4 Characters.", field: 'pass' }
: (!/^([a-z0-9_-]+)$/i.test(username)) ? { error: "Username contains invalid characters.", field: 'name' }
: false
);
(function () {
// ... all vars and functions are in this scope only
// still maintains access to all globals
}());
@zhuochun
zhuochun / app.commonjs.js
Created June 14, 2012 13:12 — forked from kwhinnery/app.commonjs.js
Ti.include, browser, and CommonJS module
//CommonJS style
var mod = require('browser.ti.module');
mod.sayHello('Kevin');