Jump to content

[HELP] Decimal number


..:D&G:..

Recommended Posts

Hello peeps, is there a way of getting a text using guiGetText and check if it's a normal whole number?

I want to output an error if the player enters a number with , or ., or a number and a letter, I want to check if the number the player entered in a memo is a whole number.

Thanks.

Link to comment
  • Moderators

Hi,

You can do it with a simple regex:

function isValidNumber(number) 
    return string.find(number, "^[+-]?%d+$") and true or false 
end 

Explainations:

^begining of the string
[+-]?followed by an optional + or a -
%d+followed by a digit (so from 0 to 9) one or multiple times
$followed by the end of the string (so nothing should be after the whole number)

Test it here: http://ideone.com/pyVUMb

Regards,

Citizen

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...