Seven Mathew
Seven Mathew

Reputation: 33

How to check for invalid argument in JS?

What can I do to attain the below thing... The argument generated is bit weird!

function function1(argument1,argument2)
{
if argument1 = "
") do something;
}

"argument1" and "argument2" are generated by the CMS. I can't do anything with those contents.

Either it will generate:

<script type='text/javascript'>
document.write(function1("argument1","argument2"));
</script>

OR

<script type='text/javascript'>
document.write(function1("
","argument2"));
</script>

Upvotes: 1

Views: 444

Answers (1)

MrCode
MrCode

Reputation: 64526

You can use String.prototype.trim():

function function1(argument1,argument2)
{
    if(argument1.trim() == ''){
        // do something
    }
}

If you're worried about old browsers, you can implement the trim function yourself, see this question.

Upvotes: 1

Related Questions