简体   繁体   English

正则表达式匹配精确词

[英]Regex match exact word

I have two inputs for registration part of my project: 我在项目的注册部分有两个输入:

  1. password <input type="password" ng-model="userData.password"> 密码<input type="password" ng-model="userData.password">
  2. confirm password <input type="password" ng-model="userData.confirmPassword"> 确认密码<input type="password" ng-model="userData.confirmPassword">

I am using ng-pattern to check if userData.confirmPassword is exactly same as userData.password using this: 我正在使用ng-pattern使用以下命令检查userData.confirmPassword是否与userData.password完全相同:

<input ng-pattern="^userData.password$" ng-model="userData.confirmPassword">

The problem with the current code is that: 当前代码的问题是:

  • If password is stackoverflow and confirm passwors is 123stackoverflow123, the regex will still match and will return true for my form. 如果密码为stackoverflow并确认密码为123stackoverflow123,则正则表达式仍将匹配,并为我的表单返回true。

What regex can I place to match only if the whole text is matching? 仅当整个文本匹配时,我才能放置哪些正则表达式进行匹配?

根据文档,建议进行以下更改:

<input ng-pattern="{{userData.password}}" ng-model="userData.confirmPassword">

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

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