3

I am having hard time finding out how can I get AngularJS not to ignore whitespaces in strings. Im trying to validate password requirements with AngularJS directive and regex pattern and problem is that I dont want to allow leading or trailing whitespace in password.

Here is fiddle http://jsfiddle.net/GX5Kr/9/

var regex = /^(?=.*[0-9])(?=.*[a-zA-Z])([a-zA-Z0-9]{5,})$/;
8
  • [SPACE][SPACE][SPACE][SPACE][SPACE]foo[SPACE][SPACE][SPACE][SPACE][SPACE] reports length 3 instead of 13 - are you sure it doesn't trim the output? Commented Jan 16, 2014 at 18:47
  • No trimming in fiddle Commented Jan 16, 2014 at 18:49
  • There is nothing in the regex that allows for leading/trailing spaces since the final constraint is [a-zA-Z0-9]{5,} and its all wrapped with ^$ anchors. Must be something else. Commented Jan 16, 2014 at 18:54
  • I DONT want to allow whitespaces. Commented Jan 16, 2014 at 18:59
  • 1
    Yes. That is not my problem. Problem is angularjs striping all whitespaces off from variables. That way i cant never check them. See fiddle before commenting... Commented Jan 16, 2014 at 19:05

1 Answer 1

8

This question is a duplicate of Get trailing white space from input type password to scope?

You're probably looking for ng-trim="false". This will update your model including spaces typed into your <input>.

I updated your fiddle for proof. http://jsfiddle.net/GX5Kr/10/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.