PHP preg_match for only numbers and letters, no special characters

后端 未结 3 1919
[愿得一人]
[愿得一人] 2021-02-06 04:04

I don\'t want preg_match_all ... because the form field only allows for numbers and letters... just wondering what the right syntax is...

Nothing fancy ... just need to

3条回答
  •  心在旅途
    2021-02-06 04:36

    If you just want to ensure a string contains only alphanumeric characters. A-Z, a-z, 0-9 you don't need to use regular expressions.

    Use ctype_alnum()

    Example from the documentation:

    
    

    The above example will output:

    The string AbCd1zyZ9 consists of all letters or digits.
    The string foo!#$bar does not consist of all letters or digits.
    

提交回复
热议问题