문제

What is the regex using javax.validation.constraints @Pattern for user not to be able to choose username such as "admin" or "manager"?

I am not understanding how to use "?!" to indicate word which must be excluded. Could you please suggest some examples with exclusion of just "admin" string and I will figure out the rest.

도움이 되었습니까?

해결책

You can use the following expression which will match any value that is not manager or admin:

^(?!(admin|manager)).*$

and if you want to disallow the user to choose usernames which contain manager or admin anywhere in the string like usr_admin, myManager_101, etc ..

Then you can use the following:

^(?!.*?(admin|manager)).*$
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top