Valitation rule

gabi 03 Nov, 2019
I want a validation rule, but I am no able to create the JavaScript myself.
I named the rule customval
The field must contain one of 5 numbers: BLDCT-0001 or BLDCT-0002 or BLDCT-0003 or BLDCT-0004 or BLDCT-0005
Otherwise an error message must show up.
I hope someone can create this JavaScript for me. I know where to put it.
healyhatman 03 Nov, 2019
Just use regex.

^BLDCT-000[1-5]$
gabi 04 Nov, 2019
I have no idea what regex is nor how to use it.
I found a homepage which looks like some kind of tool: https://regexr.com/
Not sure if that is what you are talking about.

I have been testing with this script, but it is just working for a range of numbers 1-5

jQuery.fn.form.settings.rules.customval = function(value, param) {
var x = 5;
if (Number(value) > Number(x)) {
return false;
}else{
return true;
}
};
healyhatman 04 Nov, 2019
Answer
There's a "regex" option in the validation tab of the field, put what I said in that. Or use javascript's "test()" function. Like
jQuery.fn.form blahblahblah = function(value, param) {
var patt = new RegExp("^BLDCT-000[1-5]$");
return patt.test(value);
}
But really, just use the regex option in the validation tab.
gabi 04 Nov, 2019
Dont see the regex option in the validation tab of the field, so I used the script
jQuery.fn.form.settings.rules.customval = function(value, param) {
var patt = new RegExp("^BLDCT-000[1-5]$");
return patt.test(value);
}

But I dont get any error message if typing fx BLDCT-0009 which is actually not allowed

Valitation rule image 1

https://linedancetoender.dk/index.php/bordertraef-da/bordertraef-tilmelding-2020-da
gabi 04 Nov, 2019
oh wait a min. Maybe my own fault. Let me check that
gabi 04 Nov, 2019
Sorry it is working now.
I have 4 text fields in my form for those codes, and I only put the validation rule into the first field.
Now everything is working - thank you so much for your help
This topic is locked and no more replies can be posted.