[英]regex for not allowing <> special characters
HI All I am using regex for not allowing special characters嗨,我正在使用正则表达式不允许特殊字符
I want to allow \\ / * ?我想允许 \\ /* ? % |
% | : , ( ) - _ ;
: , ( ) - _ ; # .
# . + characters only.
+ 仅限字符。 Its working fine for all except <>.
除了 <> 之外,它的所有工作都很好。
Can any one help me with this.谁能帮我这个。 May be I am doing some mistake in my code.
可能是我在我的代码中犯了一些错误。
Thanks here is my code:谢谢这是我的代码:
public validate(val: any) {
let regExp = /^[ \\/*?%|()-_;#.+:, a-zA-Z0-9]+$/;
//if (!val.match(regExp) || val.length < 1)
if (!regExp.test(val) || val.length < 1)
return false;
else
return true;
}
With the escaping of the -
as mentioned in the comment by @georg on your question, it would be:随着的逃逸
-
如在由@georg对你的问题的评论中提及,那就是:
let regExp = /^[ \\/*?%|()\-_;#.+:, a-zA-Z0-9]+$/;
Apparently, you may need to also escape the /
character inside:显然,您可能还需要转义里面的
/
字符:
let regExp = /^[ \\\/*?%|()\-_;#.+:, a-zA-Z0-9]+$/;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.