[英]Validation on Field : JavaScript regex required for Field
以下是字段值应为的要求-否则应产生错误
格式必须为只有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
检查一下 ,并显示所有说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.