简体   繁体   中英

Check if textbox is blank in javascript

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.

Use $.trim() function to remove all white-space from beginning and end of the string

if ($.trim($('#txtEmail').val()) != "")
{
     // do something
}

javascript

if((document.getElementById('bereich').value).length==0)

or jquery

if ($('#txtEmail').val()).length==0)

or

  if ($.trim($('#txtEmail').val()).length==0)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM