0

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
Wes Foster
  • 8,770
  • 5
  • 42
  • 62
Juna serbaserbi
  • 205
  • 2
  • 12

1 Answers1

3

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" />
Zorken17
  • 1,896
  • 1
  • 10
  • 16
  • It works in here Zorken17 and i tried in [jsfiddle](http://jsfiddle.net/junaserbaserbi/6feuLyvq/1/) and it works also, but if i copy into my php file, it doesn't worked, why? – Juna serbaserbi Nov 09 '15 at 15:53
  • @Junaserbaserbi you inserted the jquery CDN in your code? – Zorken17 Nov 09 '15 at 15:54
  • Give me your php/html code, so I can see what's wrong. – Zorken17 Nov 09 '15 at 15:56
  • [imgur](http://i.imgur.com/F6MEcOQ.jpg), it's wierd Zorken, i'm really confused, whereas I just copied your code. – Juna serbaserbi Nov 09 '15 at 15:59
  • 1
    @Junaserbaserbi you need to insert jQuery to your project for it to work. And if you have not linked jQuer it won't work. – Zorken17 Nov 09 '15 at 16:02
  • Please insert your php/html code for us to help you further. – Zorken17 Nov 09 '15 at 16:03
  • you mean insert this: ? – Juna serbaserbi Nov 09 '15 at 16:04
  • I can see it, but not sitting on a computer so can't test I fully. I will do that as son as I get to one. – Zorken17 Nov 09 '15 at 16:05
  • I already put that thing from the beginning (i just copying from you), you can see fbmeledak.com/ztest1.php right? but it doen't worked, why? – Juna serbaserbi Nov 09 '15 at 16:08
  • I don't know, where have you put the jquery CDN, in the head of your html page? You maybe need to put the code in a $(document).ready() scope. – Zorken17 Nov 09 '15 at 16:13
  • i put into [tophead](http://fbmeledak.com/ztest1.php), [bottomhead](http://fbmeledak.com/ztest2.php), [topbody](http://fbmeledak.com/ztest3.php), [bottombody](http://fbmeledak.com/ztest4.php), it's not work either – Juna serbaserbi Nov 09 '15 at 16:20
  • Let me come back to you when I am sitting at a computer so I can debug your code. – Zorken17 Nov 09 '15 at 16:21
  • you can right click and **view page source** to see the result, ok Zorken, i'm waiting for you. thank you. – Juna serbaserbi Nov 09 '15 at 16:24
  • I know, but I am sitting on a mobile device. – Zorken17 Nov 09 '15 at 16:27
  • ok anytime Zorken. I feel like an headache now, this is 11.30pm in Indonesia right now. – Juna serbaserbi Nov 09 '15 at 16:30
  • Ok, so I see that you are not so familiar with javascript. If you want to have the code in the header it must be surrounded by $ ( document) .ready ( ) that I wrote before, or else you can insert it after your html elements. Javascript can not be executed before the elements are loaded. I changed my code here above, so take it and copy in the same way it will work. – Zorken17 Nov 09 '15 at 17:35
  • OK, it's worked finally. You alright Zorken, I'm newbie in Jquery. Thanks for your help Zorken. +9 for you. – Juna serbaserbi Nov 09 '15 at 17:42
  • Zorken, please help me again in [this]( http://stackoverflow.com/questions/33622363/disabled-a-submit-button-is-not-working-after-i-press-a-single-quotes), it is still your code yesterday. – Juna serbaserbi Nov 10 '15 at 03:30
  • Zorken, please help me again in [this](http://stackoverflow.com/questions/33669459/confusing-about-this-cookies-in-redirecting-system), because no body wants to answer me Zorken. – Juna serbaserbi Nov 12 '15 at 12:07