Page 1 of 1

count the number of digits entered in a field

Posted: November 28th, 2018, 7:55 am
by ABOUBALLACK
Hello,
is it possible to check if the phone number entered is good or not?
Example: If the number has 9 digits, I want to be able to display an error when the user enters a 7-digit number.
If so, how to implement the code?
Thank you

Re: count the number of digits entered in a field

Posted: November 28th, 2018, 8:31 am
by josh
If the phone number is entered as an alphanumeric variable you can use the length function to see how long it is.

Re: count the number of digits entered in a field

Posted: November 28th, 2018, 8:37 am
by Gregory Martin
If the value is numeric, you can also calculate the base-10 log of the number, though you would check that it equals 8, not 9:
if int(log(PHONE_NUMBER)) <> 8 then

Re: count the number of digits entered in a field

Posted: November 28th, 2018, 9:10 am
by josh
Alternatively you can just test if the number is less than the smallest 9 digit number:
if PHONE_NUMBER < 100000000 then
This won't work if a phone number can start with zero but neither will the solution using log. If the number can start with zero you need to use alpha.