Check if textbox is blank in javascript
11,702
Solution 1
Use $.trim()
function to remove all white-space from beginning and end of the string
if ($.trim($('#txtEmail').val()) != "")
{
// do something
}
Solution 2
javascript
if((document.getElementById('bereich').value).length==0)
or jquery
if ($('#txtEmail').val()).length==0)
or
if ($.trim($('#txtEmail').val()).length==0)
Author by
Narendra
I am a .net, C++ developer for more than 6 years. I have cleared MCTS 70-515 certification. I am interested in playing computer games(mainly racing). I also like photography. Currently I am working in WPF and C++. http://narendra-mallik.branded.me/
Updated on June 28, 2022Comments
-
Narendra almost 2 years
I have a email textbox in my web page. When user submits the page I am doing some client side validation using javascript. I can get the value of the textbox and compare it to know if it has any data or not. But in case user enters only blank spaces how will I bypass it.
I am using below mentioned code.
// Check the format of email only if it has some data. // otherwise no checking is needed. if ($('#txtEmail').val() != "") { // do something }
Thanks in advance.