Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @echo off
- cls
- :: This is a positive integer and will return TRUE
- Call :isNum 54
- echo %retval%
- :: This is a negative integer and will return TRUE
- Call :isNum -13
- echo %retval%
- :: This is not an integer and will return FALSE
- Call :isNum 15a7
- echo %retval%
- :: This is a decimal and will return FALSE
- Call :isNum 12.7
- echo %retval%
- exit /b
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :: Determines if a string argument is an integer value
- ::
- :: Arguments: %1 - the string to check
- :: Returns: TRUE if the string is an integer, FALSE otherwise
- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
- :isNum
- setlocal enabledelayedexpansion
- set num=%1
- :: Strip the leading negative symbol if there is one
- if "!num:~0,1!"=="-" set num=!num:~1!
- :: Use all digits as delimiters. If there is anything left, it's not an integer.
- for /f "delims=1234567890" %%A in ("%num%") do (
- set new_num=%%A
- )
- set is_num=TRUE
- if not "!new_num!"=="" set is_num=FALSE
- endlocal&set retval=%is_num%
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement