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
SF7SF7 

Not Allow Decimals

Hi All

 

I have some input fileds in vf page where i can eneter values and i do not want users able to enetr decimals(us locale) or cammas( ,)[france locale)  how can i do it 

i tried to change the filed decimal length to zero and then user is able to enetr and upon saving it deletes 

but i do not want the user to enter at all 

 

  <apex:inputField value="{!wrapper.ocr.Total_Client_Spend__c}"  required="true" />

 

 <apex:inputField id="UnitPrice" value="{!wrapper.ocr.UnitPrice}"  required="true"/>

 

 

Best Answer chosen by Admin (Salesforce Developers) 
Richa KRicha K

This may be one of the solution :

<apex:page showHeader="true" StandardController = "Account">
<apex:form>
 <SCRIPT type="text/Javascript">
    
      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
      
   </SCRIPT>
      <apex:inputfield value="{!Account.NumberOfEmployees}" id="txtChar" onkeypress="return isNumberKey(event)" />

</apex:form>
 </apex:page>

 Thanks,

Shailesh Patil

 

PS: Tested working

All Answers

colemabcolemab

How about using an apex:Actionsupport tag to tie an event like on change to a javascript code?  Then that javascript code could remove the decmial for you or alert the user.

Richa KRicha K

This may be one of the solution :

<apex:page showHeader="true" StandardController = "Account">
<apex:form>
 <SCRIPT type="text/Javascript">
    
      function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
      
   </SCRIPT>
      <apex:inputfield value="{!Account.NumberOfEmployees}" id="txtChar" onkeypress="return isNumberKey(event)" />

</apex:form>
 </apex:page>

 Thanks,

Shailesh Patil

 

PS: Tested working

This was selected as the best answer
SF7SF7

I used java Script as you said it worked and i added charChode != 46 for decimals and it worked .

 

Can you tell me in the java script what are the numbers which represent letters, because i need to give access to letters like K and M for thoushands and millions and B for Billions.