You can actually use this and regex by attaching the webform.states library to your form.
In your custom_module.libraries.yml:
webform.states:
version: VERSION
js:
/modules/contrib/webform/js/webform.states.js: {}
dependencies:
- webform/webform.behaviors
- core/drupal.states
Then in your form, simply add:
$form['#attached']['library'][] = 'custom_module/webform.states';
Now you can use all of these:
Drupal.states.Dependent.comparisons.Object = function (reference, value) {
if ('pattern' in reference) {
return (new RegExp(reference['pattern'])).test(value);
}
else if ('!pattern' in reference) {
return !((new RegExp(reference['!pattern'])).test(value));
}
else if ('less' in reference) {
return (value !== '' && parseFloat(reference['less']) > parseFloat(value));
}
else if ('less_equal' in reference) {
return (value !== '' && parseFloat(reference['less_equal']) >= parseFloat(value));
}
else if ('greater' in reference) {
return (value !== '' && parseFloat(reference['greater']) < parseFloat(value));
}
else if ('greater_equal' in reference) {
return (value !== '' && parseFloat(reference['greater_equal']) <= parseFloat(value));
}
else if ('between' in reference || '!between' in reference) {
if (value === '') {
return false;
}
var between = reference['between'] || reference['!between'];
var betweenParts = between.split(':');
var greater = betweenParts[0];
var less = (typeof betweenParts[1] !== 'undefined') ? betweenParts[1] : null;
var isGreaterThan = (greater === null || greater === '' || parseFloat(value) >= parseFloat(greater));
var isLessThan = (less === null || less === '' || parseFloat(value) <= parseFloat(less));
var result = (isGreaterThan && isLessThan);
return (reference['!between']) ? !result : result;
}
else {
return reference.indexOf(value) !== false;
}
};
Like so:
'#states' => [
'visible' => [
':input[name="custom_field"]' => ['value' => ['greater_equal' => '40']],
],
]