1

I am trying to match a alphanumber string that MUST have numbers and MUST have letters in it.

How do I do that?

1
  • So exactly which characters are allowed in an alphanumber string? Are spaces allowed? How about newlines or periods? How about Unicode "letters" from another language? Please be more precise and give examples of strings you want to match and examples of strings you do NOT want to match. Commented Dec 12, 2011 at 22:54

2 Answers 2

1

Use lookaheads:

^(?=.*\d)(?=.*[a-zA-Z]).*$

In order for this match to succeed at least one ASCII number and at least on ASCII letter must be a part of the string.

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

Comments

1

The first thing that comes to mind would be a regex like this:

(\d.*[a-zA-Z].* | [a-zA-Z].*\d.*)

So, a digit, anything, and a letter somewhere, or a letter, anything and a digit somewhere with no beginning or end of string markings.

It's super broad, but does that help at all?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.