0

I have a sign-up form that just sends us an email when submitted. Can I trim the suggested username field to prevent multiple words from being entered? Or perhaps automatically eliminate the spaces upon submit to form a single word?

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.