REGEX min. 4 characters, maximum 11, allow you to use space and special characters

I have a regular expression in a RegularExpressionValidator.NET control: ^\w{4,11}$ Works fine. It allows string lengths from 4 to 11. I would like this to allow space and special characters such as "æ" "ø" "å" (Danish characters).

Any suggestions?

+6
source share
3 answers

How about ^.{4,11}$ ? Or just check that the line is between 4 and 11. If that doesn't work, I think it's easier to combine characters that you don't allow ...

+6
source

Since you are talking about .net \w , you should include all Unicode code points with a property letter. This means that all letters from all languages ​​in Unicode are already available in \w

So you just need to add a space and everything will be ready:

 ^[\w ]{4,11}$ 

matches "Foo æ ø å" in my test.

"[\ w]" is a character class that now includes all characters included in \w and a space. If you need more characters, just add them inside the class.

\p{L} will only be letters, you can use this if you do not want to allow numbers.

+4
source

You can use this:

^[\wæøå]{4,11}$

0
source

Source: https://habr.com/ru/post/903107/


All Articles