Ask Your Question

How do I use validate_re to check integers?

asked 2013-09-25 04:09:09 -0500

robrwo gravatar image

I am passing port parameters to some custom resources, and would like to validate them as integers, using something like:

define foo(
  $port = 1000,
) {
  require stdlib
  validate_re($port, '^\d+$')


This works for the default value of $port, but whenever I specify a different value for the port, e.g.

foo( 'myfoo': port => 1001 }

it fails with a message that says the port parameter doesn't match the regex.

I don't understand why this is failing.

edit retag flag offensive close merge delete


Same code working fine on my machine. Try printing the $port parameter in the function itself using notify{"${port}":}, it may gives you any clue.

rahul khengare gravatar imagerahul khengare ( 2013-09-25 07:42:11 -0500 )edit

I've tried that. That's why I asked?

robrwo gravatar imagerobrwo ( 2013-09-26 05:34:24 -0500 )edit

And the notify spits out '1001'?

Ancillas gravatar imageAncillas ( 2013-10-19 00:10:01 -0500 )edit

@Ancillas: yes.

robrwo gravatar imagerobrwo ( 2013-10-21 08:32:13 -0500 )edit

I've noticed in the .erb templates that sometimes variables are integers, other times strings. So I'm thinking that may be what's going on with this.

robrwo gravatar imagerobrwo ( 2014-04-11 03:58:43 -0500 )edit

4 Answers

Sort by ยป oldest newest most voted

answered 2013-09-26 01:55:02 -0500

golja gravatar image

updated 2013-10-21 09:17:29 -0500

Or you co