Skip to content

Instantly share code, notes, and snippets.

@solancer
Created December 1, 2016 12:05
Show Gist options
  • Save solancer/e9317e1985f1b9a09d2925b794a1a18e to your computer and use it in GitHub Desktop.
Save solancer/e9317e1985f1b9a09d2925b794a1a18e to your computer and use it in GitHub Desktop.
HTML input filters
<script type="text/javascript">
$(document).ready(function() {
var masks = {
'int': /[\d]/,
'float': /[\d\.]/,
'money': /[\d\.\s,]/,
'num': /[\d\-\.]/,
'hex': /[0-9a-f]/i,
'email': /[a-z0-9_\.\-@]/i,
'alpha': /[a-z_]/i,
'alphanum': /[a-z0-9_]/i,
'alphanumlower':/[a-z0-9_]/,
'alphaspace': /[a-z ]/i,
'alphanumspace': /[a-z0-9_ ]/i,
'alphanumspacelower':/[a-z0-9_ ]/
};
$('input[data-mask]').each(function(idx) {
var mask = $(this).data('mask');
var regex = (masks[mask]) ? masks[mask] : mask;
$(this).filter_input({ regex: regex, live: true });
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment