admin管理员组

文章数量:1295295

How to validate if a parameter is exits in the querystring or not in the node.js ?

I am validating like this

if(prm1 == null)
return error

But actually in the console.log(prm1) says undefined..

How to validate this exactly ?

How to validate if a parameter is exits in the querystring or not in the node.js ?

I am validating like this

if(prm1 == null)
return error

But actually in the console.log(prm1) says undefined..

How to validate this exactly ?

Share asked Apr 5, 2013 at 12:44 RajRaj 8374 gold badges15 silver badges24 bronze badges 1
  • try if(prm), it exists, or if(!prm) it doesnot exist – Xavier S. Commented Apr 5, 2013 at 12:59
Add a ment  | 

1 Answer 1

Reset to default 6

If the parameter is not present in your queryString it is returned as undefined. The parameter wouldn't return null because it wasn't initialised.

try this :

if(typeof prm1 != 'undefined')
    return "error";

本文标签: javascripthow to check if a parameter is present in the querystring in nodejsStack Overflow