测试脚本是否包含字母和数字以外的批处理代码 [英] batch code to test if script contains anything other than Letters and Numbers
本文介绍了测试脚本是否包含字母和数字以外的批处理代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想知道是否可以测试变量以查看其是否包含字母和数字以外的其他内容?我需要有此名称以限制用户名规范.我在下面有一种示例脚本.
I was wondering if it is possible to test a variable to see if it contains anything other than Letters and numbers? I need to have this in order to limit username specs. I have a kind of example script below.
:top
echo enter a name
set /p name=">"
If contains (Anything other than letters/numbers/dashes) echo Invalid Name. & goto top
echo thank you!
pause
谢谢大家!
我认为这可能是重复的,但是我不知道要寻找什么来查找其他帖子...每当我搜索与我的问题相关的任何内容时,它都会在文本文件中显示查找和替换或其他不相关的内容.如果有人可以找到重复的邮件,请告诉我,我将结束此问题.谢谢.
推荐答案
这仅允许使用字母,数字和破折号:
This allows only letters, numbers, and dashes:
@echo off & setlocal
:top
set /P "name="Enter a name: "
setlocal enabledelayedexpansion
echo(!name!| findstr /i "[^a-z0-9-]" >NUL && (
endlocal
set /P "=Invalid name. " <NUL
goto top
)
endlocal
echo Thank you %name%!
pause
这篇关于测试脚本是否包含字母和数字以外的批处理代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文