0

I am having a problem with the regex expressions. I am trying to match a string, which should contain at least one uppercase charracter and at least one number from 0-9 Lets say we have these strings:

 sdsFg3n match asdfghf not match aewag3t not match 

The order of the charracters and numbers is not important.. The string should just contain them. The expression I tried is [A-Za-z0-9], but that doesn't help me...

18
  • 2
    ^(?=.*[A-Z]).*\d.*.... Next time, you should post your attempts. Commented Nov 5, 2015 at 15:23
  • 1
    @AvinashRaj I don't think we should encourage this kind of questions; Your solution doesn't really help OP understanding how to solve problems in real life. Commented Nov 5, 2015 at 15:26
  • 2
    @ВасилЕмилов post an example where my regex failed to handle? Commented Nov 5, 2015 at 15:31
  • 1
    @bobblebubble exactly, I didn't change the pattern . I just added the text Next time, Commented Nov 5, 2015 at 15:50
  • 1
    @ВасилЕмилов based on Avinash regex, if you want to allow only alphas and digits, see demo here. Try ^(?=.*?[A-Z])[a-zA-Z]*\d[a-zA-Z\d]*$ Commented Nov 5, 2015 at 16:18

1 Answer 1

1

How about something simple, like this?

([A-Z].*[0-9])|([0-9].*[A-Z]) 
Sign up to request clarification or add additional context in comments.

1 Comment

This solution works for me, here a sample implementation /[A-Z].*[0-9]|[0-9].*[A-Z]/.test('Hotch1') this return true if instead of Hotch1 you try 'hotch1' the result is false. Thanks

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.