From ee7fd53b5202012ea864d25eb3861c74ad134e3a Mon Sep 17 00:00:00 2001 From: kohsuke Date: Fri, 6 Feb 2009 21:39:38 +0000 Subject: [PATCH] added more validator type git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15083 71c3de6d-444a-0410-be80-ed276b4c234a --- .../java/hudson/util/FormFieldValidator.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/src/main/java/hudson/util/FormFieldValidator.java b/core/src/main/java/hudson/util/FormFieldValidator.java index d70defc3c6..4831497c32 100644 --- a/core/src/main/java/hudson/util/FormFieldValidator.java +++ b/core/src/main/java/hudson/util/FormFieldValidator.java @@ -610,4 +610,27 @@ public abstract class FormFieldValidator { error(errorMessage); } } + + /** + * Verifies that the 'value' parameter is an integer >= 0. + * + * @since 1.282 + */ + public static class NonNegativeInteger extends FormFieldValidator { + public NonNegativeInteger() { + super(null); + } + + protected void check() throws IOException, ServletException { + try { + String value = request.getParameter("value"); + if(Integer.parseInt(value)<0) + error(hudson.model.Messages.Hudson_NotAPositiveNumber()); + else + ok(); + } catch (NumberFormatException e) { + error(hudson.model.Messages.Hudson_NotANumber()); + } + } + } } -- GitLab