1

I tried to use regexes in C#

^(?=.*\d)(?=.*[a - z])(?=.*[A - Z])(?=.*[!@#$%^*])(?=.*[a-zA-Z]).{6,20}$

but \d comes as an error if i put [0-9] instead it wont work as desired

This should check the string has a uppercase, lowercase, symbol and a number

h25
  • 11
  • 6

1 Answers1

0

You should use [0-9]. Probably it is more correct... \d will catch non-european digits like рен (it is a Devanagari digit).

For the reason:

you probably wrote:

 var rx = new Regex("\d");

But in this way the \d is an escape sequence of the string instead of being a regex.

Write

var rx = new Regex(@"\d");

to deactivate the escape expansion of strings.

xanatos
  • 106,283
  • 12
  • 188
  • 265