Last active
December 12, 2015 09:48
-
-
Save arlg/4753833 to your computer and use it in GitHub Desktop.
Input functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Clears the input on focus, restore its initial content on blur if nothing entered by user | |
var input = $('input[type=text]'); | |
input.focus(function() { | |
var el = $(this); | |
if(el.val() === el.attr('data-placeholder')){ | |
$(this).val(''); | |
} | |
}).blur(function() { | |
var el = $(this); | |
if(el.val() === ''){ | |
el.val(el.attr('data-placeholder')); | |
} | |
}); | |
//Allows only numerical value | |
//Numerical input | |
$(".numerical").keypress(function(event){ | |
var theEvent = event || window.event; | |
var key = theEvent.keyCode || theEvent.which; | |
key = String.fromCharCode( key ); | |
var regex = /[0-9]|\./; | |
if( !regex.test(key) ) { | |
theEvent.returnValue = false; | |
if(theEvent.preventDefault) theEvent.preventDefault(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment