jQuery detect if textarea is empty

前端 未结 11 934
抹茶落季
抹茶落季 2020-12-25 11:05

I am trying to determine if a textarea is empty if a user deletes what is already pre-populated in the textarea using jQuery.

Anyway to do this?

This is what

11条回答
  •  悲哀的现实
    2020-12-25 11:24

    This will check for empty textarea as well as will not allow only Spaces in textarea coz that looks empty too.

     var txt_msg = $("textarea").val();
    
     if (txt_msg.replace(/^\s+|\s+$/g, "").length == 0 || txt_msg=="") {
        return false;
      }
    

提交回复
热议问题