Created
June 9, 2012 07:04
-
-
Save Zenger/2899902 to your computer and use it in GitHub Desktop.
Javascript/PHP numbers Only
This file contains hidden or 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
/* Without jQuery */ | |
/* Example | |
<input id="myInput" name='credit-card' value='' /> | |
*/ | |
document.getElementById('myInput').onkeyup = function() { | |
this.value = this.value.replace(/[^\d]/gi , ''); | |
}; | |
/* With jQuery */ | |
jQuery('myInput').bind('keyup' , function() { | |
$(this).val ( $(this).val().replace(/[^\d]/gi , '') ); | |
}); |
This file contains hidden or 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
/* Without jQuery */ | |
/* Example | |
<input id="myInput" name='credit-card' value='' /> | |
*/ | |
document.getElementById('myInput').onkeyup = function() { | |
this.value = this.value.replace(/[^\d]/gi , ''); | |
}; | |
/* With jQuery */ | |
jQuery('myInput').bind('keyup' , function() { | |
$(this).val ( $(this).val().replace(/[^\d]/gi , '') ); | |
}); |
This file contains hidden or 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
<?php | |
function onlynumbers ($var = null) { | |
return preg_replace('/[^\d]/i', '', $var); | |
} | |
echo onlynumbers("good123"); | |
?> | |
/* This gist was created for a specific task, and mainly to keep the non jquery that it won't be lost somewhere. */ | |
/* This makes use of regular expressions */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment