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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.