Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if textbox has empty value

Tags:

jquery

I have the following code:

var inp = $("#txt");  if(inp.val() != "") // do something 

Is there any other way to check for empty textbox using the variable 'inp'

like image 524
KJai Avatar asked Oct 14 '09 09:10

KJai


People also ask

How do I check if a text box is empty?

IsNullOrEmpty() function has a boolean return type and returns true if the string is either null or empty and otherwise returns false . We can use the String. IsNullOrEmpty() function on the string inside the TextBox. Text property to check whether the text inside the text box is empty or not.

How can check empty TextBox value in jQuery?

To check if the input text box is empty using jQuery, you can use the . val() method. It returns the value of a form element and undefined on an empty collection.

What is the value of an empty text box?

when you do not enter anything in INPUT box then its value become UNDEFINED.


1 Answers

if (inp.val().length > 0) {     // do something } 

if you want anything more complicated, consider regex or use the validation plugin which takes care of this for you

like image 195
wiifm Avatar answered Nov 16 '22 00:11

wiifm