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('');
     }
});

Leave a Reply

Your email address will not be published. Required fields are marked *