标题: [已结]麻烦各位老师帮完善批处理程序:检验日期合法性
[打印本页]
作者: bsthq
时间: 2009-2-9 00:33
标题: [已结]麻烦各位老师帮完善批处理程序:检验日期合法性
刚接触批处理,许多地方搞不懂如何实现,有劳各位老师能帮我完善下面的批处理,实现下面的要求吗?谢谢!
我想在::a和::b处加入批处理语句,对月份[1-12]和日期[1-31]范围加以判断,数字不能为0,或大于12,或大于31,字母、空格都不准许输入,输入错误返回到start处。
如何有好的处理方法也希望老师提出来.谢谢了!
@echo off
:start
set /p input=请输入月份[1-12]:
::a
set /p date=请输入日期[1-31]:
::b
echo
pause
goto start
end
[
Last edited by HAT on 2009-2-9 at 02:13 ]
作者: BC
时间: 2009-2-9 00:55
findstr配合一下?
作者: moniuming
时间: 2009-2-9 01:21
@echo off
:start
set /p input=请输入月份[1-12]:
echo %input%|findstr /v "[0-9]"&&(echo error&goto :start)
if %input% leq 0 (echo error&goto :start)
if %input% gtr 12 (echo error&goto :start)
:start_
set /p dt=请输入日期[1-31]:
echo %dt%|findstr /v "[0-9]"&&(echo error&goto :start_)
if %dt% lss 1 (echo error&goto :start_)
if %dt% geq 32 (echo error&goto :start_)
echo 月:%input% 日:%dt%
goto :start
作者: bsthq
时间: 2009-2-9 01:43
谢谢老师,我试了一下,可以实现要求,不过如果是空值并且回车的话,就没有卡控到,会继续往下执行的。参照老师的方式做了如下修改:
i@echo off
:start
set input=
set /p input=请输入月份[1-12]:
if "%input%"=="" goto start
echo %input%|findstr /v "[0-9]"&&(echo error&goto :start)
if %input% leq 0 (echo error&goto :start)
if %input% gtr 12 (echo error&goto :start)
:start_
set dt=
set /p dt=请输入日期[1-31]:
if "%dt%"=="" goto :start_
echo %dt%|findstr /v "[0-9]"&&(echo error&goto :start_)
if %dt% lss 1 (echo error&goto :start_)
if %dt% geq 32 (echo error&goto :start_)
echo 月:%input% 日:%dt%
goto :start