Check if textarea has any characters (and ignore spaces) before sending

I have a simple check .val() == ""with jQuery if textarea is empty or not before sending. It works, but it counts spaces.

How can I ignore spaces in this check?

// Post guestbook; Check on frontend before submitting
function postGuestbook() {
    if ($('.post-form textarea').val() == "") 
    {
        $('div.message.error').show();
        return false
    }
    else {
        $('.post-form input[type="submit"]').attr('disabled', 'disabled');
        return true;
    }
}
+3
source share
1 answer
...
if ($.trim($('.post-form textarea').val()) == "") {
    ... 

http://api.jquery.com/jQuery.trim/

+6
source

Source: https://habr.com/ru/post/1759466/


All Articles