Hello! On my registration form I ask for a username and I only want a letters,numbers and underscores(_) in the username. How would I go about checking that? Thanks for any help!
NardCake 30 Posting Pro in Training
Recommended Answers
Jump to Post@NardCake
Hello! On my registration form I ask for a username and I only want a letters,numbers and underscores(_) in the username. How would I go about checking that? Thanks for any help!
You meaning using Regex to do that?
Try this:
([A-Za-z0-9\-\_]+)
Jump to Posthere is another one... :).
<?php $string = 'abcd_23$_&'; if(!preg_match('/^[\w-]+$/',$string)){ echo 'oops! not a valid username'; } else{ echo 'Valid Username'. $string; }
All 7 Replies
phorce 131 Posting Whiz in Training Featured Poster

LastMitch
veedeoo 474 Junior Poster Featured Poster
NardCake 30 Posting Pro in Training
phorce 131 Posting Whiz in Training Featured Poster
NardCake 30 Posting Pro in Training
phorce 131 Posting Whiz in Training Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.