Only letterNumber, but not all numbers

I know how to do a regex to check if it is just an alphanumeric without spaces:

/^[0-9a-zA-Z]+$/

but how can I add to this regex so that it cannot contain only numbers, so for example this is not true:

08128912382

Any ideas?

+4
source share
4 answers

"Must contain only letters and numbers, and at least one letter" equivalent "must contain a letter surrounded by numbers or letters:

/^[0-9a-zA-Z]*[a-zA-Z][0-9a-zA-Z]*$/

I would like to add that this answer shows a way that you can think of a problem, so regexp is easier to write. This should not be the best solution to the problem. I just took what you had and gave it a push in the right direction.

( ZER0, Tomalak OGHaza ):

  • , , . , , ( !):

    • /^[0-9]*[a-zA-Z][0-9a-zA-Z]*$/ - , ,
    • /^[0-9a-zA-Z]*[a-zA-Z][0-9]*$/ - ,
  • , , :

    • /^(?=.*[a-z])/ - , 1
  • , , , :

    • /^(?!\d+$)/ - ,

, , , ( )

, , , .

+7

:

/^(?=.*[a-z])[0-9a-z]+$/i
+5

, ,

/^(?!\d+$)[0-9a-zA-Z]+$/

RegExr

+2

, , . , , , , , , :

/^[0-9]*[a-z][0-9a-z]*$/i

Note that it will return trueif you check against a string of the type "A", for example, because in this case all numbers are considered optional.

+1
source

All Articles