简体   繁体   English

角度输入ng-pattern消毒正则表达式

[英]angular input ng-pattern sanitize regex

Can anyone recommend a regex that will reject any string with characters that should be escaped for use in an angular form input like... 任何人都可以推荐一个正则表达式,拒绝任何字符串,该字符串应该被转义以用于角形式输入,如...

<input name="name"  type="text" ng-pattern="*REGEX HERE*" ng-model="selectedExercise.name" />

And yes I know that this isn't a good way to sanitize user input. 是的,我知道这不是消毒用户输入的好方法。 Under the hood I am using also using $sanitize before communicating to the backend and doing full sanitizing on the backend too. 我正在使用$ sanitize,然后在后端进行通信并在后端进行完全消毒。

If you are looking to prevent XSS type attacks, then the way to do this is to sanitize the input when it is being rendered to the user and not at time of capture. 如果您希望防止XSS类型攻击,那么执行此操作的方法是在将输入呈现给用户时而不是在捕获时清理输入。

If your application is rendering using Angular, then it automatically safely encodes all output on binding. 如果您的应用程序使用Angular进行渲染,则它会自动安全地编码绑定时的所有输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM