-1

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());
      }
2
  • Please edit your question and add the minimal required HTML to reproduce your problem. Commented Jan 7, 2022 at 6:08
  • Please do not repeat asking the very same question over and over if your initial question gets closed. Instead, try to remedy the shortcomings pointed out in the close reason by editing your initial question. Commented Jan 7, 2022 at 6:31

1 Answer 1

1

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
}

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.