开发者

Prevent multiple words form field PHP MySQL

开发者 https://www.devze.com 2023-03-18 18:12 出处:网络
I have a sign-up form that just sends us an email when submitted. Can I trim the sug开发者_开发知识库gested username field to prevent multiple words from being entered? Or perhaps automatically elimin

I have a sign-up form that just sends us an email when submitted. Can I trim the sug开发者_开发知识库gested username field to prevent multiple words from being entered? Or perhaps automatically eliminate the spaces upon submit to form a single word?


You should look into preg_replace($patterns, $replacements, $string); In your case, you would want:

// \s+ means 1 or more whitespace characters.
// '' means that the whitespace will be replaced by emptiness.
// so this should return a string which replaces all whitespace with nothing
preg_replace("#\s+#g", '', $string);
0

精彩评论

暂无评论...
验证码 换一张
取 消