Regex Match - Word must include at least 1 upper case letter and at least 1 digit. Length should be 8 or more than 8

I’m struggling to create a regex match for the following conditions,

  1. Word must include at least 1 upper case letter and at least 1 digit
  2. Length of the word should be 8 or more than 8
  3. No spaces should be there

Appreciate your help on this.

Hi @Tharusha_Jayadeera

Could you please share any sample input and the output you are looking for?

1 Like

Hello

Got a sample and outputs?

“7P 1111951460 84VV3G3I”

I need to match - 84VV3G3I from the above text

Hello

Try this pattern:
\b[A-Za-z0-9]{8}\b
Preview result here

Have you got additional samples to help us understand more?

2 Likes

Hi,

This match allows only digits and only letters as well.

But it needs to have at least 1 upper case letters and at least 1 digit both to match

Hello

You might need to add a second step where it check for a Capital Letters.

Like try this regex pattern:
[A-Z]
Then count the results -
IF

0 = valid
<0 = invalid

@prasath17 - any thoughts?

Hi @Tharusha_Jayadeera could you just try this
Regex.IsMatch(var,"((?=.\d)(?=.[a-zA-Z])(?=.*[@#$%]).{15,32})")

Where var will be your input…This is an sample expression , but you can edit it accourding to your logic

1 Like

You can check here…

1 Like

hi,

this pattern does not match 84VV3G3I from this “7P 1111951460 84VV3G3I”

@Tharusha_Jayadeera let me give you the exact expression itself

Hi this does not match 84VV3G3I
image

Hi @Tharusha_Jayadeera could you try this
((?=. \d)(?=. [A-Z]).{8,32})
for spaces include /s

Hi @nikhil.girish
Thanks for following up. But still the same. It does not match

image

^(?=.*[A-Z])(?=.*\d)[a-zA-Z\d]{8,}$

If you need to consider unicode letters also, test with the pattern below:

(?=\w*\d)(?=\w*\p{Lu})[\p{L}\d]{8,}

2 Likes

Wow, I think this will work. This accepts lower case as well. But I think I can manage that.
@ptrobot Thanks a lot.

Thank you for the support @prasath17, @Steven_McKeering, @nikhil.girish

1 Like

Hi @Tharusha_Jayadeera,
You are welcome! Just out of curiosity, in which scenario does it match lower case that you don’t want? If you don’t want it to match lower case at all you can just change it to:

(?=\w*\d)(?=\w*\p{Lu})[\p{Lu}\d]{8,}

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.