I’m struggling to create a regex match for the following conditions,
- Word must include at least 1 upper case letter and at least 1 digit
- Length of the word should be 8 or more than 8
- No spaces should be there
Appreciate your help on this.
I’m struggling to create a regex match for the following conditions,
Appreciate your help on this.
Hi @Tharusha_Jayadeera …
Could you please share any sample input and the output you are looking for?
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?
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
You can check here…
hi,
this pattern does not match 84VV3G3I from this “7P 1111951460 84VV3G3I”
Hi this does not match 84VV3G3I
^(?=.*[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,}
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
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.