[英]Regular expression still allowing tab character to be pasted into form field
Does anyone know why my regex below is still allowing a tab character whitespace to be pasted into a form field? 有谁知道为什么我下面的正则表达式仍然允许将制表符字符空格粘贴到表单字段中? I think I wrote it correctly... 我想我写的没错...
/^[a-zA-Z\s]+$/g
Suggestion from answer to post: 从答案到帖子的建议:
self.City = ko.observable(model.City).extend({ required: true, maxLength: 30, pattern: /^[a-zA-Z ]+$/ });
\\s
allows a tab and many more whitespace chars. \\s
允许使用制表符和更多空白字符。
If you need a literal space replace \\s
with a space. 如果需要文字空间,请用空格替换\\s
。
You do not need the global modifier either. 您也不需要全局修饰符。
Use 采用
/^[a-zA-Z ]+$/
In Knockout, use 在淘汰赛中,使用
self.City = ko.observable(model.City)
.extend({ required: true })
.extend({ maxLength: 30 })
.extend({ pattern: {
message: 'Only letters and spaces are allowed.',
params: '^[a-zA-Z ]+$'
}});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.