ctype_alpha but allow spaces(php)

前端 未结 3 637
南方客
南方客 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:14

    this is what I would do

    if (!ctype_alpha(str_replace(' ', '', $fname)))
    

    this allows for spaces only, but if you want to allow more than just spaces, like punctuation or what not, read up on str_replace, it allows for arrays

    str_replace(array(' ', "'", '-'), '', $fname)
    

    I'm suggesting this because First Name may have apostrophe and last name may also have dashes

提交回复
热议问题