jQuery trim input val

Hello Experts,

Can someone help me understand why this if statement is not working?
Can i use the jQuery "trim" in this way on form input filed?

$(requiredInput).blur(function() {
		
  if (($.trim($(this).val() === "")) || ($.trim($(this).val().length <= 5))) {

  }
}

Open in new window


Thanks!!!
RefaelAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

haloexpertsexchangeCommented:
trim requires a string not boolean values which is what you are giving it.
http://api.jquery.com/jQuery.trim/

Maybe what you wanted was something more like this?
if (($.trim($(this).val() )=== "") || ($.trim($(this).val()).length <= 5)) {

  }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RefaelAuthor Commented:
Perfect, Thank you haloexpertsexchange
Can you explain what this it mean a string here?  .val() )
0
haloexpertsexchangeCommented:
.val() gets you the value from which ever element you are currently accessing with $(this).val();
This is not to be confused with the text of an element.
Inputs have both and do not necessarily have the same information in both or even have both filled in.
http://api.jquery.com/val/
http://api.jquery.com/text/
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

RefaelAuthor Commented:
Hi haloexpertsexchange, thank you again.

So you basically it means that when i use "trim" i need to refer to the "text" (string) and not to the "value". by having this "val() )" . am i right?
0
RobOwner (Aidellio)Commented:
no - you need to use trim on a string.  you can also use it on val() / text() as they both return strings but you can't use it on a boolean such as true / false, which you were doing with your comparison:

...val() === "" <======== this returns a Boolean not a string
0
RefaelAuthor Commented:
Thank you tagit :-) now i understand.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.