I'm trying to display a Javascript error message if a certain range value is entered in a field. example: If the version entered is between 13.0.x to 13.8.5, an error message will be displayed. I'm trying the code below but it's not working. Any help would be greatly appreciated. Thank you
$('#custom_fields_1234').on('blur', function() {
$('.errorMessage').remove();
if ($(this).val().split('.')[0] < val => 13.0.0 && =< 13.8.5) {
$('.custom_fields_1234').append(errorMessage());
}
You can split the version number to check, for example.
function isVersionInRange( version, maxVersion, minVersion ) {
const [major, minor, patch] = version.split('.').map(Number)
const [maxMajor, maxMinor, maxPatch] = maxVersion.split('.').map(Number)
const [minMajor, minMinor, minPatch] = minVersion.split('.').map(Number)
// if the version is greater than the maxVersion
if (
major > maxMajor ||
(major === maxMajor && minor > maxMinor) ||
(major === maxMajor && minor === maxMinor && patch > maxPatch)
) {
return false
}
// if the version is less than the minVersion
if (
major < minMajor ||
(major === minMajor && minor < minMinor) ||
(major === minMajor && minor === minMinor && patch < minPatch)
) {
return false
}
return true
}