Ad Code

Collection of jQuery Input Filters

✅ Collection of jQuery Input Filters

1. Allow Only Numeric

javascript
$('.allow-numeric').on('input', function () { this.value = this.value.replace(/[^0-9]/g, ''); });

2. Allow Only Alphabets (a-z, A-Z) and Spaces

javascript
$('.allow-alpha-space').on('input', function () { this.value = this.value.replace(/[^a-zA-Z\s]/g, ''); });

3. Allow Only Alphanumeric and Spaces

javascript
$('.allow-alnum-space').on('input', function () { this.value = this.value.replace(/[^a-zA-Z0-9\s]/g, ''); });

4. Allow Decimal Numbers (e.g., 123.45)

javascript
$('.allow-decimal').on('input', function () { this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*)\./g, '$1'); });

5. Allow Alphabets Only (No Space)

javascript
$('.allow-alpha').on('input', function () { this.value = this.value.replace(/[^a-zA-Z]/g, ''); });

6. Allow Alphanumeric (No Space)

javascript
$('.allow-alnum').on('input', function () { this.value = this.value.replace(/[^a-zA-Z0-9]/g, ''); });

7. Allow Username Style (Alphanumeric, Underscore, No Space)

javascript
$('.allow-username').on('input', function () { this.value = this.value.replace(/[^a-zA-Z0-9_]/g, ''); });

8. Allow Name Format (Alphabets, Space, Dot)

javascript
$('.allow-name').on('input', function () { this.value = this.value.replace(/[^a-zA-Z.\s]/g, ''); });

9. Allow Phone Number Format (Digits, Space, Plus, Hyphen)

javascript
$('.allow-phone').on('input', function () { this.value = this.value.replace(/[^0-9+\-\s]/g, ''); });

10. Allow Address Format (Alphanumeric, Comma, Dot, Hyphen, Space)

javascript
$('.allow-address').on('input', function () { this.value = this.value.replace(/[^a-zA-Z0-9,\.\-\s]/g, ''); });

✅ Example Usage in HTML:

html
<input type="text" class="allow-numeric" placeholder="Only Numbers"> <input type="text" class="allow-alpha-space" placeholder="Alphabets with Space"> <input type="text" class="allow-alnum-space" placeholder="Alphanumeric with Space"> <input type="text" class="allow-decimal" placeholder="Decimal"> <input type="text" class="allow-phone" placeholder="Phone Number"> <input type="text" class="allow-address" placeholder="Address">
 

 

Post a Comment

0 Comments