Check a login character pattern

Asked

Viewed 151 times

1

When using the class Regex of the C#

I wanted the string nomeLogin

  • do not allow it to start with numbers or special characters.

  • only allow "_" or "-" or "." as special characters.

  • 2 characters minimum with first letter and lower case.

  • maximum 20 characters.

2 answers

2

I think this works, I haven’t tested and I can’t guarantee that you’re taking all the situations:

var regex = new Regex("^[a-zA-Z][-a-zA-Z0-9_\.]*$");

I put in the Github for future reference.

I also don’t know if you specified correctly what you needed. The specification is already weird saying what it can’t, the right thing is to say what it can.

2

good I managed to solve, so for those who need ta there the tested answer:

var regex = new regex("^[a-z][A-Za-z0-9_.-]{1,19}$");

Browser other questions tagged

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