1

I need to check to see if a string has at least a letter OR number. What would be the best way to check that?

1
  • There are a million dups for this question. Why not perform a search? Commented Jun 9, 2011 at 18:11

1 Answer 1

4

Use a simple regex:

/[0-9a-zA-Z]/.test(some_string);
Sign up to request clarification or add additional context in comments.

3 Comments

Clean and simple. Extract to a variable if you want to re-use the expression.
/[A-Z0-9]/i.test(str) slightly shorter
/[0-9a-z]/i would also be possible, just for the record.

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.