PHP - regex to allow letters and numbers only

前端 未结 5 776
谎友^
谎友^ 2020-11-27 06:21

I have tried:

preg_match(\"/^[a-zA-Z0-9]\", $value)

but im doing something wrong i guess.

5条回答
  •  清歌不尽
    2020-11-27 07:06

    As the OP said that he wants letters and numbers ONLY (no underscore!), one more way to have this in php regex is to use posix expressions:

    /^[[:alnum:]]+$/
    

    Note: This will not work in Java, JavaScript, Python, Ruby, .NET

提交回复
热议问题