count the number of digits entered in a field

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
ABOUBALLACK
Posts: 14
Joined: September 22nd, 2016, 9:24 am

count the number of digits entered in a field

Post 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
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: count the number of digits entered in a field

Post by josh »

If the phone number is entered as an alphanumeric variable you can use the length function to see how long it is.
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: count the number of digits entered in a field

Post 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
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: count the number of digits entered in a field

Post 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.
Post Reply