Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Mindelusions
Created November 2, 2012 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Mindelusions/4003537 to your computer and use it in GitHub Desktop.
Save Mindelusions/4003537 to your computer and use it in GitHub Desktop.
Titanium - Field Mask
/*
* @ Developed by Nyvra (http://www.nyvra.net)
* @ Last release: 13/10/2011
*/
Mask = {
mask: function(_field, _function) {
_field.value = _function(_field.value)
},
postcode: function(v) {
v = v.replace(/D/g,"");
v = v.replace(/^(\d{5})(\d)/,"$1-$2");
return v.slice(0, 9);
},
phone: function(v) {
v = v.replace(/\D/g,"");
v = v.replace(/^(\d\d)(\d)/g,"($1) $2");
v = v.replace(/(\d{4})(\d)/,"$1-$2");
return v.slice(0, 14);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment