neil.walker Posted September 19, 2017 Share Posted September 19, 2017 Hello,How do I add validation to parameters, e.g. I have a string that is requested but I want to ensure it is only numeric, or max length of 10, or not empty, etc. so when I try to run the report it stops me and shows the error?I've also tried raising an exception in the stored procedure the reports call, but instead of a message, the report fails badly with a stack trace in Studio preview mode. I rather hoped if all else failed it would show the custom exception message rather than simply failing.I've searched and searched the internet and the documentation and absolutely nothing comes up. Surely this is a common enough thing that should be in the documentation...thanks for any help. Link to comment Share on other sites More sharing options...
reportdev Posted September 19, 2017 Share Posted September 19, 2017 Try this pattern on the input control. ^[0-9]{10}$Dont use any double quotes or special characters around this pattern.java implementation if you are interested public static void main(String[] args) { String s2 = "1234567891"; String regnum = "^[0-9]{10}$"; Pattern pattern2 = Pattern.compile(regnum); Matcher matcher2 = pattern2.matcher(s2); System.out.println(matcher2.matches()); } Link to comment Share on other sites More sharing options...
neil.walker Posted September 21, 2017 Author Share Posted September 21, 2017 thanks, that took some doing trying to find the 'pattern'. Seems the entire 'edit' option for a report is missing from the documentation.But can I ask why ticking 'mandatory' on the input control shows it with an asterisk in the report but does not actually do anything, i.e. I can leave it blank and it's still happy.... Link to comment Share on other sites More sharing options...
neil.walker Posted September 21, 2017 Author Share Posted September 21, 2017 Thanks, seemed to work after testing, but is there a way to disallow blank entries? I couldn't figure out the regex to put in the pattern (I'd rather not write code) and selecting 'mandatory' seems to do absolutely nothing to the field other than put a '*' next to the field name. Link to comment Share on other sites More sharing options...
reportdev Posted September 21, 2017 Share Posted September 21, 2017 The same pattern ^[0-9]{10}$ is working to disallow the blank entries. please checkRemove the Mandatory option, its not necessary as the pattern match will not allow the user to go forward without entering correct pattern. Link to comment Share on other sites More sharing options...
neil.walker Posted September 21, 2017 Author Share Posted September 21, 2017 Ok, but when I enter this exactly as you put, it gives an error if the length is wrong, but on a blank entry it just allows it. Do I need to do anything else other than the pattern?I think there's something a little flaky going on with the validation. If I change it from text to number and say the min is 1000 and the max is 9999, if I enter a number too small it gives correct answer, if I enter 1234567890 it lets it through, and if I enter any other number, e.g. 12345 I get this: There was an error on the server. Try again or contact site administrators. (Error UID: d50cf057-2dbf-41fa-8470-babbe62dbc71)Regarding the mandatory query, I guess that's a separate question, but it doesn't seem to do anything on any input other than put a * next to the name. thanks. Link to comment Share on other sites More sharing options...
reportdev Posted September 22, 2017 Share Posted September 22, 2017 ok. I just realized that I missed something from your question. I missed the OR function of the pattern. ^[0-9]{0,10}$Use this pattern. sorry about it my friend. Link to comment Share on other sites More sharing options...
neil.walker Posted September 28, 2017 Author Share Posted September 28, 2017 Thanks for all the help. But the following still allows blank. Am I missing something because a standard regex disallows blank but Jasper is allowing it. Setting 'mandatory' does nothing either^[0-9]{10,10}$ Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now