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
MayankDkPantMayankDkPant 

Restricting Decimal Input

Hi,

 

My scenario is : I have a field of Number type and whose decimal point is set to 0.

 

If user enters any decimal data then it should show a validation message "Only numeric Values". But I can not achieve this. Can any one tell me how to use Reges to restrict user from entering any decimal no.

 

I am facing two problems. -

 

1. Can we have Regex on Numeric type field.

2. REGEX(NPS_Score__c ," ^[-+]?\\d+(\\.\\d+)?$"). i am using this expression to check if it contains and decimal then it will return true and error message will be flashed. I am getting "Incorrect Argument Type error".

 

Any help will be appreciated. Thank in advance.

 

With Regards,

Mayank Pant

AmitSahuAmitSahu
Can you try index of dot in the field and see if it's there or not.? If an index is returned then throw the error..
MayankDkPantMayankDkPant

There is no function index available. Can you tell me how can I achieve this? Thanks.

AmitSahuAmitSahu
You can probably use :

CONTAINS(TEXT(numberField),'.")

If the above returns true then error
MayankDkPantMayankDkPant

Thanks for this.

 

I have set decimal places to 0 for my numeric field. If I enters any data with decimal value say 7.5 then saves it, it does not throw any error message as System validation rule which triggers before custom validation rule change it to 7 and therefore it does not throw error.

 

Now if I select 2 or 1 decimal place for the numeric field in data type, then it will throw the error and user has to enter only numeric data. But in my related list the value is shown as say 7.00 which is what business does not requires. Is there any way that this value should only be shown as 7 instead of 7.00.

 

Am I making it clear, what is the requirement?

 

Thanks for all this.

 

With Regards,

Mayank Pant

AmitSahuAmitSahu
So now the issue is with Related List column , is it ?
MayankDkPantMayankDkPant

Yes. Is there any way to do it.

 

Thanks.

sfdcfoxsfdcfox

By the way, you can verify the number is a whole number using the validation rule: "FLOOR( NumberField__c ) != NumberField__c".

 

The column should honor your decimal settings. Are you displaying that value through a formula field? You might need to change the number of decimal places on the formula.

Ed HoldermanEd Holderman
Since this never got answered I will clarify the question.  If you define a numeric field with zero decimal places, the user is still allowed to enter decimals on the page.  When they submit their changes, the system automatically truncates the decimals _before_ executing any validations.  The result is that there is no validation you can write to catch this because there are no decimals by the time it gets to validation.  The user thinks they entered decimals but they are silently truncated and don't know their entry has been changed.  Any ideas on how to prevent the user from entering decimals without having to change the field definition to having decimals and adding validation?