Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

Restrict characters in input field using javascript

by
Category:javascript
javascript
Restrict characters in input field using javascript

This script allows you to set a character words a user can enter into a textarea or text field generate notice this words not allowed eg. (Terms of Service reminder: Providing email, Skype, or phone number is only allowed if it is needed as part of the service.) You may also like How to specific character to start string to create array using php and PHP htmlspecialchars_decode() Function.

HTML Code

<textarea required="" id="description_post" class="form-control" name="description"></textarea>
<span id="postError" style="color: red;"></span>

Javascript Code

$('#description_post').keyup(function(){
     if (/\b(?=\w)(email|Skype|phone number)\b(?!\w)/i.test($(this).val())) {
             $('#postError').html('Terms of Service reminder: Providing email, Skype, or phone number is only allowed if it is needed as part of the service.');
     } else {
             $('#postError').html('');
     }
});

0 Comments


Html code work in comment box


Related Post