Reputation: 3117
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.
Upvotes: 3
Views: 12389
Reputation: 31920
Use $.trim()
function to remove all white-space from beginning and end of the string
if ($.trim($('#txtEmail').val()) != "")
{
// do something
}
Upvotes: 13
Reputation: 176896
javascript
if((document.getElementById('bereich').value).length==0)
or jquery
if ($('#txtEmail').val()).length==0)
or
if ($.trim($('#txtEmail').val()).length==0)
Upvotes: 3