function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jose Lopez 18Jose Lopez 18 

How to set a minimum and a maximum on a apex:inputField type='range' and type='number'

I'm trying to use an apex:inputField to ask for user input and store the input in an object's field. i.e. 
<apex:inputfield type="number" value="{!case.CustomField__c}" />
My custom field is read/write and it's of type number. I would like to just restrict the maximum number to input for the user. Let's say I want the user to input a number between 1 and 10. I have tried this, but I get an error.
<apex:inputField type="number" min="1" max="5" value="{!case.CustomField__c}" />
The error message is: Unsupported attribute min in <apex:inputField>

I have also tried to use <apex:inputField type="range" /> but the same error applies. Ultimately I could use the html tag <input> but storing the value to my object's field would not work.

Any guidance would be appreciated, thanks!
Jasper WallJasper Wall
Hi Jose,
You can use Javascript to restrict your inputField to take the values between 1 and 5, try like this,
 
<apex:inputfield type="number" id="mynum" value="{!case.CustomField__c}" onChange="validate()"  />
<script type="text/javascript">
function validate(){
   var value=document.getElementById("mynum").value;
   if(value>5){
         alert('maximum limit reached');
   }
  if(value<1){
         alert('minium limit reached');
  }
}
</script>

Mark it as the best Answer if it helps,

Thanks,
Balayesu