Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- <script>
- $(document).ready(function () {
- // Filter input box lenght
- var maxLength = 15;
- $('#counter').html(maxLength + " characters left");
- $('#input1').keyup(function (e) {
- var currentlen = $('#input1').val().length;
- if (currentlen <= maxLength) {
- $('#counter').html(maxLength - currentlen + " characters left");
- } else {
- $(this).val($(this).val().substring(0, maxLength));
- }
- });
- //Filter number sahaja
- $("#input2").keydown(function (e) {
- if (e.shiftKey) {
- e.preventDefault();
- }
- if (e.keyCode == 46 || e.keyCode == 8) {} else {
- if (e.keyCode < 95) {
- if (e.keyCode < 48 || e.keyCode > 57) {
- e.preventDefault();
- }
- } else {
- if (e.keyCode < 96 || e.keyCode > 105) {
- e.preventDefault();
- }
- }
- }
- });
- });
- </script>
- </head>
- <body>
- <fieldset>
- <label><span>Input 1: </span></label><input type="text" id="input1"/><span id="counter"></span><br/><br/>
- <label><span>Input 2: </span></label><input type="text" id="input2"/>
- </fieldset>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement