Hey guy's
I need a piece of code that validates a username so it's only allowed lower case letters, numbers, underscores and dashes.
No spaces, dots ect.
Thank's!
Username Validation
Started by Bioshox, May 23 2010 01:42 PM
2 replies to this topic
#1
Posted 23 May 2010 - 01:42 PM
|
|
|
#2
Posted 23 May 2010 - 01:47 PM
You could use a regular expression: ^[a-z0-9_-]*$
#3
Posted 24 May 2010 - 03:38 AM
Yep, WingedPanther is right. If you're not sure how to use the regular expression, here's an example using preg_match :
<?php
$username = "some_username"; //e.g. $_POST['username']
if(preg_match("/^[a-z0-9_-]*$/", $username)) {
//Valid username
}else{
//Invalid username
}
?>


Sign In
Create Account


Back to top









