当前位置: 动力学知识库 > 问答 > 编程问答 >

php - how can i allow a question mark in this script?

问题描述:

elseif (preg_match("/[^a-z\.^A-Z\.^0-9\._]/",$_POST['content'])) { echo "Comments can only fill normal English letters (a-Z) or numbers!"; }

I need it to allow only "? or !" since people might ask questions in the comment box, how can i do this?

thanks

网友答案:

"/[^a-z.^A-Z.^0-9._\?]/" will add question marks to your match, but this overall method is brute force and gross.

网友答案:

You can make special characters literal by prepending \ (backslash), for example \? and \!. To match a-z, A-Z, 0-9, underscores, literal periods, literal exclamation marks, and literal question marks in a single line, you could use the following: ^[a-zA-Z0-9_\.\!\?]+$.

I'm not quite sure what specific format you're aiming for... Your current regex doesn't seem to match anything sensible.

分享给朋友:
您可能感兴趣的文章:
随机阅读: