Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
谁能告诉我如何检查以检查 6 位值 5 位可以是字母数字,但第 6 位必须是使用 VB 的 ASP 代码中的数字
我会使用正则表达式,因为您可以检查格式和长度,如果需求发生变化,您会很灵活(例如“更改请求:最后一位不能为零”)
str = "12aB34" Set myRegExp = New RegExp myRegExp.IgnoreCase = True myRegExp.Pattern = "^[A-Z0-9]{5}\d$" isValid = myRegExp.Test(str) ' returns True in this case
如果您的值仅固定为 6 位,则可以使用Mid功能。如果您的值不固定为 6 位并且您需要检查最后一位,您可以使用Right函数和isNumeric检查。
例如:
<% is_numeric = isNumeric(Right(myValue,1)) %>
或者
<% is_numeric = isNumeric(Mid(myValue,6,1)) %>