From bfe6cf68b3b09f5927ec8f12f6661f45e9c1be58 Mon Sep 17 00:00:00 2001 From: Joseph Yaworski Date: Mon, 28 Mar 2016 13:18:28 -0400 Subject: Add validate_email_address function --- lib/puppet/parser/functions/is_email_address.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 lib/puppet/parser/functions/is_email_address.rb (limited to 'lib/puppet/parser/functions/is_email_address.rb') diff --git a/lib/puppet/parser/functions/is_email_address.rb b/lib/puppet/parser/functions/is_email_address.rb new file mode 100644 index 0000000..ab8d075 --- /dev/null +++ b/lib/puppet/parser/functions/is_email_address.rb @@ -0,0 +1,21 @@ +# +# is_email_address.rb +# + +module Puppet::Parser::Functions + newfunction(:is_email_address, type: :rvalue, doc: <<-EOS +Returns true if the string passed to this function is a valid email address. + EOS + ) do |arguments| + if arguments.size != 1 + raise(Puppet::ParseError, 'is_email_address(): Wrong number of arguments '\ + "given #{arguments.size} for 1") + end + + # Taken from http://emailregex.com/ (simpler regex) + valid_email_regex = %r{\A([\w+\-].?)+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z} + return (arguments[0] =~ valid_email_regex) == 0 + end +end + +# vim: set ts=2 sw=2 et : -- cgit v1.2.3 From 79c871322f92bd03206ab392f9f2972f3ace97ea Mon Sep 17 00:00:00 2001 From: David Schmitt Date: Mon, 18 Apr 2016 09:46:30 +0100 Subject: (MODULES-3271) Ensure that is_email_address works on unsupported rubies --- lib/puppet/parser/functions/is_email_address.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/puppet/parser/functions/is_email_address.rb') diff --git a/lib/puppet/parser/functions/is_email_address.rb b/lib/puppet/parser/functions/is_email_address.rb index ab8d075..4fb0229 100644 --- a/lib/puppet/parser/functions/is_email_address.rb +++ b/lib/puppet/parser/functions/is_email_address.rb @@ -3,7 +3,7 @@ # module Puppet::Parser::Functions - newfunction(:is_email_address, type: :rvalue, doc: <<-EOS + newfunction(:is_email_address, :type => :rvalue, :doc => <<-EOS Returns true if the string passed to this function is a valid email address. EOS ) do |arguments| -- cgit v1.2.3