Skip to content

Instantly share code, notes, and snippets.

@rodrigopinto
Created July 18, 2011 18:56
Show Gist options
  • Select an option

  • Save rodrigopinto/1090325 to your computer and use it in GitHub Desktop.

Select an option

Save rodrigopinto/1090325 to your computer and use it in GitHub Desktop.
Mais feio que encoxar a mãe no tanque...
FormFieldMask = {
money: {
event: 'keyup',
regex: /[^\d,]/g,
handler: function(event){
var field = event.target;
field.setValue(field.value.replace(FormFieldMask.money.regex, ''));
}
},
integer: {
event: 'keyup',
regex: /[^\d]/g,
handler: function(event){
var field = event.target;
field.setValue(field.value.replace(FormFieldMask.integer.regex, ''));
}
},
// Magically applies the masks defined above
apply: function(){
for (attr in FormFieldMask){
if (FormFieldMask.hasOwnProperty(attr) && attr != 'apply'){
eval("$j('."+attr+" input')."+FormFieldMask[attr].event+"(FormFieldMask."+attr+".handler);");
}
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment