Jump to content

Validate Username


harchew

Recommended Posts

you would use regular expresions, i believe there is another forum specifically for these questions:

http://www.phpfreaks.com/forums/index.php/board,43.0.html

----

im not so good with regex in php but you could do:

<?php

$string = "USER._NAME23";	// ex valid username

if(preg_match("/[^a-zA-Z0-9\._]/i",$string) == 0){
// valid characters
if(preg_match("/[0-9]/i",$string) == 0){
	// No Numbers Found
	echo("Username must contain at least 1 number");
}
if(preg_match("/[a-z]/i",$string) == 0){
	// No Letters Found
	echo("Username must contain at least 1 character");
}
$strlen = strlen($string);
if($strlen < 8 && $strlen > 16){
	echo("Username must be between 8 and 16 characters in length");
}
}else{
echo("You have illegal characters in your username, Legal characters include: A-Z, 0-9, a period (.), and an underscore ( _ )");
}

?>

 

hope this helps,

Link to comment
https://forums.phpfreaks.com/topic/92380-validate-username/#findComment-473336
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.