I would like to check if a variable has only numeric characters, is date and if it's length is exactly 13 characters. I have this:
Code: Select all
@echo off
set numbe=1234567890123
set datte=2024-08-01
>tmp.vbs echo n=isnumeric("%numbe%") : d=isdate("%datte%") : L=len("%numbe%")
>>tmp.vbs echo WScript.Echo n ^& "#" ^& d ^& "#" ^& L
For /F "tokens=1,2,3 delims=#" %%A In ('CScript tmp.vbs //NoLogo') do (
set num=%%A
set isd=%%B
set len=%%C
)
echo %num% %isd% %len%
set num=XXX
set isd=XXX
set len=XXX
>tmp.vbs echo if isnumeric("%numbe%") then n=1 else n=0
>>tmp.vbs echo if isdate("%datte%") then d=1 else d=0
>>tmp.vbs echo if len("%numbe%")=13 then L=1 else L=0
>>tmp.vbs echo WScript.Echo n ^& "#" ^& d ^& "#" ^& L
For /F "tokens=1,2,3 delims=#" %%A In ('CScript tmp.vbs //NoLogo') do (
set num=%%A
set isd=%%B
set len=%%C
)
echo %num% %isd% %len%
if exist tmp.vbs del tmp.vbs
Code: Select all
d:\ch.cmd
Resnično Resnično 13
1 1 1
d:\>
To avoid problems with localization I am using IF to change that to 1 or 0 so I check for 0 and 1 in the variables.
Running .vbs takes a lot of time. More efficient way to use first option instead of IF statements?
Or even completely different approach?
I have .txt files with many records as this:
Code: Select all
0123456789012;2025-08-01
Thanks.
Saso