jQuery – Allow only float input

Force user to input only float data; i.e. only numbers with only one decimal point, using jQuery.

HTML Code

<input class="allowFloatOnly" type="text" />

JavaScript/jQuery:
/*global $ */
$(".allowFloatOnly").on("keypress", function (e) {

    use strict";

    return (e.which !== 8 && e.which !== 0 && (e.which !== 46 || $(this).val().indexOf(".") !== -1) && (e.which < 48 || e.which > 57)) ? false : true;
});