# [HELP] Phone Number System

## Recommended Posts

Hello

I have a phone number system
Each player has a seven-digit number

To figure out what player's number is, we use the command / number
And the server tells us:

Number is : 1234567

Please teach me to work with strings so I can do the first three digits of the phone number from the last four digits.

like this :

Number is 123-4567

plz help me

Depending on whether the 7 digit number is a real number or a string containing digits.

```function formatNumber(number)
if (type(number)=="number") then -- if 'number' was a number rather than a string
number = string.format("%07d", number) -- format the number into 7 digits padded by 0 from the front if the number is less than 1000000
end
if (type(number)~="string") then return false end -- return a false and exit function if 'number' isn't a string at this point
return string.sub(number, 1, 3) .. "-" .. string.sub(number, 4, -1) -- put characters 1 to 3, follow it with a dash, and characters 4+
end```
Edited by MrTasty
1 hour ago, MrTasty said:

Depending on whether the 7 digit number is a real number or a string containing digits.

```
function formatNumber(number)
if (type(number)=="number") then -- if 'number' was a number rather than a string
number = string.format("%07d", number) -- format the number into 7 digits padded by 0 from the front if the number is less than 1000000
end
if (type(number)~="string") then return false end -- return a false and exit function if 'number' isn't a string at this point
return string.sub(number, 1, 3) .. "-" .. string.sub(number, 4, -1) -- put characters 1 to 3, follow it with a dash, and characters 4+
end
```

thanks

• 1

## Create an account

Register a new account