简体   繁体   中英

Regex issue with AngularJS ng-pattern

I'm facing an issue with a regex using Angular JS ng-pattern. I wrote the following regex for input validation that rejects all input containing newlines, tabs and carriage return:

\A(.*)[^\t\r\n]\z

I tested using Rubular and it works. But then when I put in the ng-pattern of my .aspx the same expression with the bounds /myregex/ (that is: /\\A(.*)[^\\t\\r\\n]\\z/ ) and, obviously I specify the trigger condition "...$error.pattern", it doesn't work, namely it always considers the input as wrong. Edit: in my regex after "A(." there is also a *

Javascript won't support \\A ( start ), \\z ( end ) anchors. So i suggest you to replace them with ^ and $

^(.*)[^\t\r\n]$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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