以下是字段值的要求应该是 - 否则它应该生成错误
格式为9个字符,2个字母,后跟6个数字, 接着是一个字母
e.g。 ' 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*$)/; **
答案 0 :(得分:1)
/\b[A-z]{2}[0-9]{6}[A-z]{1}$/.test('AB332211C')
答案 1 :(得分:1)
这会有所帮助..
/^[ ]*([a-zA-Z]{2}\d{6}[a-zA-Z])[ ]*$/
[a-zA-Z]{2}
匹配两个字母字符
\d{6}
匹配后续的6位数字
[a-zA-Z]
匹配一个字母字符
答案 2 :(得分:0)
/ ^([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
Check this,显示所有解释。