From 6630861e2ba0dcddd26375055491c0511d6da81b Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 23 Jul 2025 06:52:30 +0000 Subject: [PATCH] Bug 40476: Limit item type codes to letters and numbers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds a custom jquery validator method to perform a regex test on item type codes in the admin module. Test plan: 0. Apply the patch 1. Go to http://localhost:8081/cgi-bin/koha/admin/itemtypes.pl?op=add_form 2. Try to input an "Item type" like "abc123+ 3. Note the input turns red and the message "Invalid pattern" appears. 4. Try to input an "Item type" like "ébook" 5. Note that the input is capitalised, it stays black, and there is no warning 6. Try out more combinations of things you'd like to use as item type codes --- koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt index 0f7915e365..a2dc1279c4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt @@ -551,9 +551,13 @@ ); }); + jQuery.validator.addMethod("regex", function(value, element, regex){ + return this.optional(element) || new RegExp(regex).test(value); + }, _("Invalid pattern") ); + $( "#itemtypeentry" ).validate({ rules: { - itemtype: { required: true }, + itemtype: { required: true, regex: /^[\p{L}\p{N}]+$/u }, //Allow only Unicode letters and numbers description: { required: true }, rentalcharge: { number: true }, rentalcharge_hourly: { number: true }, -- 2.39.5