ShowAll Questionssorted byDate Posted
Dee Dee Aaron

# Validation Rule: Must have at least 6 digits after the decimal point.

Hi there,
I’m looking to create a validation rule on a Geolocation field (longitude and latitude fields).
I want to ensure that the Sales reps are entering values that have a MINIMUM of 6 digits after the decimal place. How would I do this? I was thinking of creating a validation rule. But I’m not sure how to create the logic.
For example:
11.123456 (acceptable)
11.12345 (not acceptable)
Field Name: Coordinates __c
Best Answer chosen by Dee Dee Aaron
Santosh Kumar 348
Hi Dee Dee,

Please try below Regex sorry I missed the minimum 6 digit part.
`NOT(REGEX(TEXT(YourFieldName), "[0-9]+[.]{1}{1}[0-9]{6,}"))`

Regards,
Santosh Kumar

SFDC_Saurabh
I think you will have to use Javascript here.
Depending on your interface Lightning/VF, simply call a JS function...
Identifu the position of decimal in it.. with something like..
var dotPos = el.value.indexOf(".");
Now from dotPos check the length till end.. (Some String manipulation will help)
If less than 6, then you can give some validation error message...
Santosh Kumar 348
Hi Aaron,

Try using below Regex in your validation rule:
`NOT(REGEX(TEXT(YourFieldName), "[0-9]+[.]{1}{1}[0-9]{6}"))`

As Regex doesn't work with number field so you need to extract the text first and it will work s expected.

Regards,
Santosh Kumar
Dee Dee Aaron
Santosh-- your formula worked, but it only allows 6 digits after the decimal. It should accept a minimum of 6. So, if 7 didigts are entered it won't allow me to save the record. I appreciate your help!
Dee Dee Aaron
To clarify:
11.1234567 (should be acceptable)
11.123456 (should be acceptable)
11.12345 (not acceptable)
Minimum of 6. Using your formula, it won't allow me to save 7 or 8 digits after the decimal, but it needs to do this.
Santosh Kumar 348
Hi Dee Dee,

Please try below Regex sorry I missed the minimum 6 digit part.
`NOT(REGEX(TEXT(YourFieldName), "[0-9]+[.]{1}{1}[0-9]{6,}"))`