1

I am trying to use a regular expression for name field in the asp.net application.

Conditions:name should be minimum 6 characters ?

I tried the following

"^(?=.*\d).{6}$"

I m completely new to the regex.Can any one suggest me what must be the regex for such condition ?

5 Answers 5

3

You could use this to match any alphanumeric character in length of 6 or more: ^[a-zA-Z0-9]{6,}$. You can tweak it to allow other characters or go the other route and just put in exclusions. The Regex Coach is a great environment for testing/playing with regular expressions (I wrote a blog post with some links to other tools too).

Sign up to request clarification or add additional context in comments.

Comments

1

Look at Expression library and choose user name and/or password regex for you. You can also test your regex in online regex testers like RegexPlanet.

My regex suggestions are:

 ^[a-zA-Z][a-zA-Z0-9._\-]{5,}$

This regex accepts user names with minimum 6 characters, starting with a letter and containing only letters, numbers and ".","-","_" characters.

Next one:

 ^[a-zA-Z0-9._\\-]{6,}$

Similar to above, but accepts ".", "-", "_" and 0-9 to be first characters too.

If you want to validate only string length (minimum 6 characters), this simple regex below will be enough:

 ^.{6,}$

Comments

1

What about

^.{6,}$

What's all the stuff at the start of yours, and did you want to limit yourself to digits?

1 Comment

i don't want to limit to digits ,i just want to limit to the condition: minimum 6(length of the string entered) any string entered less than 6 should cause a validation
1

NRegex is a nice site for testing out regexes.

To just match 6 characters, ".{6}" is enough

Comments

1

In its simplest form, you can use the following:

.{6,}

This will match on 6 or more characters and fail on anything less. This will accept ANY character - unicode, ascii, whatever you are running through. If you have more requirements (i.e. only the latin alphabet, must contain a number, etc), the regex would obviously have to change.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.