Juna serbaserbi
Juna serbaserbi

Reputation: 227

I can't find the simplest of textarea validation

I want just a simplest textarea with validation rule by onkeypress in jQuery but NOT in HTML5, bootstrap, or angularJS. I can't find it anywhere. For example it fills by these:

Corrects: spaces, letter, number, many words,-,+,_,/,.

Incorrects: ',",!,@,#,$,%,^,%,*,space in front and last

I can do it by angularJS but not in JQuery. I just want it in jQuery pattern or another way in jQuery. If the content of textarea is not in the correct way in its pattern, the submit button hiding or disabled then. Thanks for your help.

I've been looking for references among them like these (they can be filled by ' single quote):

  1. http://www.jeasyui.com/tutorial/form/form3.php
  2. http://trevordavis.net/play/jQuery-Simple-Validate/
  3. http://www.innovativephp.com/applications/demos/jquery_form_validation_examples/textarea_validation
  4. http://jsfiddle.net/ZAaPu/
  5. https://www.daniweb.com/programming/web-development/threads/449610/textarea-validation-problem-jquery

Upvotes: 0

Views: 192

Answers (1)

Zorken17
Zorken17

Reputation: 1896

You can always try this:

$(document).ready(function() {
    $('#input').keyup(function() {
	    if(!$(this).val().match(/^(?!\s)([a-zA-Z0-9 _.)?&]){1,}$/g)) {
           $('#button').prop('disabled', true);
        }else{
           $('#button').prop('disabled', false);
        }
    });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<input id="input" />
<input id="button" type="button" value="submit" />

Upvotes: 3

Related Questions