Home > Enterprise >  Regex Expression to restrict the space character in a password field using javascript
Regex Expression to restrict the space character in a password field using javascript

Time:08-19

I have a need to put a RegEx expression over a property in a model on a MVC website that I'm working on.

The different pieces of the expression make sense to me individually, but I can't figure out how to form them together.

I have to restrict password field to letters, capital letters, numbers, and the symbols, but not space character

I then need to ensure that the following criteria is met by the user

Input must contain 1 capital letter Input must contain 1 number Input must contain one special character. Input must not contain the Space character

I've tried below regex, but space character validation is not working

^(?=.*\d)(?=.*[a-zA-Z]).{8,}$

CodePudding user response:

Maybe you get more luck with this Regex for empty string or white space I guess it was answered in a lot of ways over there

CodePudding user response:

^(?=.*\d)(?!.*\s)(?=.*[a-zA-Z]).{8,}$

This is working as expected

  • Related