字段验证:字段需要 JavaScript 正则表达式

Validation on Field : JavaScript regex required for Field

本文关键字:字段 JavaScript 正则表达式 验证      更新时间:2023-09-26

以下是字段值的要求应该是 - 否则它应该产生错误

格式仅为 9 个字符,后跟 2 个字母,后跟 6 个数字, 后跟一个字母

例如"AB332211C"

任何其他值都应使用 JavaScript 生成错误消息。谁能帮我为此创建正则表达式。

编辑:到目前为止,我已经完成了这个:帮助改进相同的内容

--------------------------------------------------------------------------
    var myAssumption = /^'d{2}[a-zA-z] 'd{6}[0-9]'d{1}[a-zA-z]$/;
--------------------------------------------------------------------------

以下链接可能有助于回答: http://www.java2s.com/Code/JavaScript/Form-Control/Mustbeatleast3charactersandnotmorethan8.htm

例子:

// Common regexs
  var regexEmail = /^(['w]+)(.['w]+)*@(['w]+)(.['w]{2,3}){1,2}$/;
  var regexUrl = /^(http:'/'/www.|https:'/'/www.|ftp:'/'/www.|www.){1}(['w]+)(.['w]+){1,2}$/;
  var regexDate = /^'d{1,2}('-|'/|'.)'d{1,2}'1'd{4}$/;
  var regexTime = /^([1-9]|1[0-2]):[0-5]'d$/;
  var regexIP = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])'.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
  var regexInteger = /(^-?'d'd*$)/; **
/'b[A-z]{2}[0-9]{6}[A-z]{1}$/.test('AB332211C')

这将有所帮助。

/^[ ]*([a-zA-Z]{2}'d{6}[a-zA-Z])[ ]*$/

[a-zA-Z]{2}匹配两个字母字符

'd{6}匹配后续 6 位数字

[a-zA-Z]匹配一个字母字符

/^([a-zA-Z]{2}''d{6}[a-zA-Z])$/

1st Capturing group ([a-zA-Z]{2}'d{6}[a-zA-Z])
[a-zA-Z]{2} match a single character present in the list below
Quantifier: {2} Exactly 2 times
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)
'd{6} match a digit [0-9]
Quantifier: {6} Exactly 6 times
[a-zA-Z] match a single character present in the list below
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)
$ assert position at end of the string

检查这个,显示所有解释。