admin管理员组文章数量:1420985
I have an input password field. I want to be able to warn the user that they cannot have any white space in there password. The trouble I'm finding is that I cant pass the trailing white space to the scope in order to detect it and warn the user that they cannot do this.
See my plunkr example: LINK
If you type in the input field the scope will return how many characters the password is and if you add white space at the end of the password the scope will not report the correct string length because it is obviously trimming any trailing white space which means I have no way to identify if the user is entering any spaces or not. So as the user adds trailing spaces the input password field will show that an extra character has been added when the scope is only reporting the length of characters without any trailing spaces.
I have an input password field. I want to be able to warn the user that they cannot have any white space in there password. The trouble I'm finding is that I cant pass the trailing white space to the scope in order to detect it and warn the user that they cannot do this.
See my plunkr example: LINK
If you type in the input field the scope will return how many characters the password is and if you add white space at the end of the password the scope will not report the correct string length because it is obviously trimming any trailing white space which means I have no way to identify if the user is entering any spaces or not. So as the user adds trailing spaces the input password field will show that an extra character has been added when the scope is only reporting the length of characters without any trailing spaces.
Share Improve this question asked Jul 12, 2013 at 18:17 Malcr001Malcr001 8,28910 gold badges46 silver badges57 bronze badges 4- 1 What's wrong with whitespace in the password? Restrictions like that just reduce the security of the password, and you should be bcrypt hashing for storage anyways. – ceejayoz Commented Jul 12, 2013 at 18:23
- possible duplicate of angularjs filters on ng-model in an input – shaunhusain Commented Jul 12, 2013 at 18:35
- Looks like you need to upgrade your angular version to take advantage of this directive (1.1.1 vs 1.0.7 in your plunkr) or you know patch your copy with the mit in the SO post linked... – shaunhusain Commented Jul 12, 2013 at 18:36
- Please post the relevant code in the question itself, don't just link. Why: meta.stackexchange./questions/118392/… – T.J. Crowder Commented Jul 12, 2013 at 18:39
1 Answer
Reset to default 8Here's the fixed plunkr solution is upgrade to 1.1.1 of angular to take advantage of ng-trim directive which allows you to turn off the trimming: http://plnkr.co/edit/FLCQY2zuRV1ZMy6WCbs8?p=preview
Upgrade to Angular 1.1.1 or higher (tested, might work in some lower versions) add this directive to your element where you have the ng-model you don't want trimmed.
ng-trim="false"
Here's the full details:
<!DOCTYPE html>
<html ng-app="plunker">
<head>
<meta charset="utf-8" />
<title>AngularJS Plunker</title>
<script>document.write('<base href="' + document.location + '" />');</script>
<link rel="stylesheet" href="style.css" />
<script data-require="[email protected]" src="https://ajax.googleapis./ajax/libs/angularjs/1.1.1/angular.min.js" data-semver="1.1.1"></script>
<script src="angular_ui.js"></script>
<script src="app.js"></script>
</head>
<body ng-controller="MainCtrl">
<form>
Pass length is {{pass.length}}<br>
<input type="password" data-ng-model="pass" data-ng-trim="false">
</form>
</body>
</html>
And the JS
var app = angular.module('plunker', ['ui.event']);
app.controller('MainCtrl', function($scope) {
$scope.name = 'World';
});
本文标签: javascriptGet trailing white space from input type password to scopeStack Overflow
版权声明:本文标题:javascript - Get trailing white space from input type password to scope? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744655641a2617948.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论