Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 用于在coldfusion中使用html进行模式验证的正则表达式_Regex_Validation_Coldfusion - Fatal编程技术网

Regex 用于在coldfusion中使用html进行模式验证的正则表达式

Regex 用于在coldfusion中使用html进行模式验证的正则表达式,regex,validation,coldfusion,Regex,Validation,Coldfusion,我有一个7位数的变量“CustCd”。第一个数字可以是数字或字母,但最后6个数字(位置2-7)必须是数字。我试图使用一个正则表达式,其中pattern=“[0-9 a-Z a-Z]{1}[0-9]{2,7}”需要类validate,但它不起作用 这是我的密码: <input type="text" name="CustCd" id="CustCd" size="7" maxlength="7" pattern="[0-9 A-Z a-z]{1} [0-9]{2,7}"

我有一个7位数的变量“CustCd”。第一个数字可以是数字或字母,但最后6个数字(位置2-7)必须是数字。我试图使用一个正则表达式,其中pattern=“[0-9 a-Z a-Z]{1}[0-9]{2,7}”需要类validate,但它不起作用

这是我的密码:

<input type="text" name="CustCd" id="CustCd" 
    size="7" maxlength="7" 
    pattern="[0-9 A-Z a-z]{1} [0-9]{2,7}" 
    title="Customer Code" class="validate required" />


这是我第一次使用正则表达式,所以我想我可能忽略了一些东西。非常感谢您的帮助。

尝试使用
^[a-zA-Z0-9]{1}[0-9]{6}$
作为您的模式。请记住,此验证是针对JavaScript正则表达式引擎进行的

<input type="text" name="CustCd" id="CustCd" size="7" maxlength="7" 
  pattern="^[a-zA-Z0-9]{1}[0-9]{6}$"  title="Customer Code" class="validate required" />
要尝试的完整示例代码

<!DOCTYPE html>
<form>
  <input type="text" name="CustCd" id="CustCd" size="7" maxlength="7" pattern="[a-zA-Z0-9]{1}[0-9]{6}" title="Customer Code" class="validate required" />
  <input type="submit">
</form>


您希望HTML输入字段如何进行自我验证?如果您使用的是HTML5验证,那么问题与CF无关。提示:“不工作”之类的描述非常模糊。相反,请简要描述实际结果,以及它与您预期的结果的差异。RE:这是我第一次使用正则表达式,尽管额外的空白提高了人类的可读性,但正则表达式引擎不是人类;-)因此,包含额外的空格实际上会更改表达式匹配的内容。因此
[0-9(空格)A-Z(空格)A-Z]
将匹配A-Z、A-Z、0-9或空格字符。“如果您使用HTML5验证”-@sjstroot,您是否100%肯定您系统的每个用户都在使用支持HTML5的浏览器?如果不是,则该模式属性对您没有任何帮助。另外,请确保在服务器端对该数据运行相同的验证。上面提到的文档也提到了这一点:模式必须匹配整个值,而不仅仅是某个子集。因此,您可能需要类似以下内容
[0-9a-zA-Z](\d{1,6})
。不是吗?如果它应该匹配整个字符串,则更像
^[a-zA-Z0-9]{1}[0-9]{6}$
。假设HTML5支持。。。
^ assert position at start of the string
[a-zA-Z0-9]{1} match a single character present in the list below
  Quantifier: {1} Exactly 1 time (meaningless quantifier)
  a-z a single character in the range between a and z (case sensitive)
  A-Z a single character in the range between A and Z (case sensitive)
  0-9 a single character in the range between 0 and 9
[0-9]{6} match a single character present in the list below
  Quantifier: {6} Exactly 6 times
  0-9 a single character in the range between 0 and 9
$ assert position at end of the string
<!DOCTYPE html>
<form>
  <input type="text" name="CustCd" id="CustCd" size="7" maxlength="7" pattern="[a-zA-Z0-9]{1}[0-9]{6}" title="Customer Code" class="validate required" />
  <input type="submit">
</form>