String with spaces - Regex Ismatch returns true when it should return false

Asked

Viewed 89 times

1

I have the following Regex

(?=.*\d)(?!.*\s)(?=.*[a-zA-Z\s]).{6,12}

If I do tests on site that test Regex, it works, in the view Model Annotation to validate works, but when I do in service regex.IsMatch(" qqq11") he returns true, where it should bring false.

  • Removing spaces from the beginning and end of the string before validating?

1 answer

2

There may be some difference between how these sites work and the Regex class.

Making tests here some websites return true for this value, others return false, what you can try to do is change the regex so it picks up the beginning and end of the line

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.