[英]ng-pattern for excluding a list of characters
I am looking for the ng-pattern for my input field which is excluding these special characters: 我正在为我的输入字段寻找ng-pattern,其中不包括以下特殊字符:
[ ] : ; | = + * ? < > / \ ,
I don't want the user input has these characters above. 我不希望用户输入的字符在上面。 Please help.
请帮忙。
You have to escape the \\
and the ]
: 您必须转义
\\
和]
:
ng-pattern="/^[^[\]:;|=+*?<>/\\,]+$/"
pattern automatically adds the /^
and the $/
so: 模式会自动将
/^
和$/
相加:
pattern="[^[\]:;|=+*?<>/\\,]+"
var app = angular.module('app', []);
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.4.3/angular.min.js"></script> <div ng-app='app'> <form name="myForm"> <input name="field" ng-model="something" ng-pattern="/^[^[\\]:;|=+*?<>/\\\\,]+$/"> {{ myForm.field.$error }} </form> </div>
This is what you are looking for 这就是你要找的
^[^[:;|=+*?<>\/\\,\]]+$
You can see what it does at the following link 您可以在以下链接中看到它的作用
this should work 这应该工作
"^[^\[\]:;|=\+\*\?<>\/\\]+$"
if it doesn't work with HTML then u can use 如果它不适用于HTML,那么您可以使用
"^[^\\\\[\\\\]:;|=\\\\+\\\\*\\\\?<>\\\\/\\\\\\]+$"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.