0

Is it possible to only accept certain parameter types (in this case digits)? If a letter or other character is entered I want to revert to a default scenario.

The noted code are the two attempts I've made.

app.get('/multi/:num?', function (request, response) {

  //if (num.match("[A-Za-z]"))
  // { num = 4}
  //if (num in (/\D/))
  //{ num = 4}

var num = (request.params.num || 4);
}
response.send(num);
Crocs123
  • 105
  • 7

1 Answers1

1

Try your route this way. app.get('multi/:num(\d+)') In express, this generally defines that route must be a digit.

Piyush Rana
  • 631
  • 5
  • 8