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
Noor FazliNoor Fazli 

How can i force the number field in apex:inputfield to accept numbers only

Hi,
Whats the right way of enforcing the datatype for a inputfield in Visualforce page?
I have a field defined as number but still can take characters.
We have another requirement where we want another input field defined as percent to accept percent only.
Please advise.
Best Answer chosen by Noor Fazli
Sagar PareekSagar Pareek
The page allows to enter the alphabets but only numbers will be comitted to the data base. The best way is enforce javaScript that can show an error on page while user enters any thing other than numbers. 
 

All Answers

BalajiRanganathanBalajiRanganathan
if you have field defined as number or percent then <apex:inputField> will allow only number or percent. you don't need to do any thing. probably check if you are saving your VF page with latest api version.
Sagar PareekSagar Pareek
The page allows to enter the alphabets but only numbers will be comitted to the data base. The best way is enforce javaScript that can show an error on page while user enters any thing other than numbers. 
 
This was selected as the best answer