ctype_alpha but allow spaces(php)

前端 未结 3 634
南方客
南方客 2021-02-09 04:58

I was wondering if one can allow spaces in a textfield when checking it with ctype_alpha. Since ctype_alpha only allows alphabetical letters, I don\'t know how to let the user e

3条回答
  •  我在风中等你
    2021-02-09 05:05

    You can do that also by simply removing space before you do ctype_alpha.

    $fname=str_replace(" ", "", $fname);
    
    if(!ctype_alpha($fname)){
      echo "Your name may only contain alphabetical letters";
    }
    

提交回复
热议问题