Regex: only alphanumeric but not if this is pure numeric

后端 未结 7 2074
北荒
北荒 2020-11-29 11:34

For instance:

\'1\'     => NG
\'243\'   => NG
\'1av\'   => OK
\'pRo\'   => OK
\'123k%\' => NG

I tried with

          


        
7条回答
  •  感动是毒
    2020-11-29 11:59

    Try with this:

    /^(?!^\d*$)[a-zA-Z\d]*$/
    

    Edit: since this is essentially the same of the accepted answer, I'll give you something different:

    /^\d*[a-zA-Z][a-zA-Z\d]*$/
    

    No lookaheads, no repeated complex group, it just verifies that there's at least one alphabetic character. This should be quite fast.

提交回复
热议问题