Mandatory fields and username restrictions on a WordPress site.

Hello!

I have a WordPress site but I have no experience with PHP. The website has an account sign up page.

I'd like to make filling out the 'First Name' and the 'Last Name' fields a requirement when users sign up for an account. I'd also like to implement 'Username' creation restrictions, for example:

The following special characters are not allowed:
" / \ [ ] : ; | = , + * ? < >

For the required fields, I can probably copy the code from the other required fields that is already in place. But the restriction I don't know how to do. Does anybody have a sample code that I can take a look at?

Thank you  in advance!
LVL 2
petaganayrAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
In case you're interested in learning PHP (kind of a requirement if you're going to make changes to WordPress functionality) this article may be able to help you find the way forward.
http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/A_11769-And-by-the-way-I-am-new-to-PHP.html
Mark BradyPrincipal Data EngineerCommented:
I would do a restriction check on the front end first using javascript but here is a way you could look for those characters on the back end (PHP).

$invalid_characters = array('"', '/', '\', '[', ']', ':', ';', '|', '=', '+', '*', '?', '<', '>');
$valid = false;
for ($i = 0; $i < strlen($username); $i++) {
	if (in_array($username[$i], $invalid_characters)) {		
		break;
	}
	$valid = true;
}

if (!$valid) {
	// do something here. Return an error
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
petaganayrAuthor Commented:
Thank you for the input. I'll be doing some testing this weekend. I will let everyone know how it went.
petaganayrAuthor Commented:
Thank you for the comments. I chose Mark's comment because I used his example and made my own lines of codes.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
WordPress

From novice to tech pro — start learning today.