FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


HomeWatched TopicsRegisterSearchDirectory
FAQMemberlistUsergroupsLog inStoresItemsBank
Google

Reply to topic Page 1 of 1
validating username
Message  

Reply with quote
Post validating username 
i have used the following code to validate the username it is working fine

=============================================
if( $username == "" ||  !preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $username) )
{
$error.="User name cannot be blank or has special characters";
}     
=============================================

it does not accept UNDERSCORE at the beginning or end however while i was testing with different special characters except for # the validation works fine for all other special characters.

for example if i enter the user name as = abc#123

in this case # sign and what comes after # sign is being ignored. so in this case the username is being read as abc ONLY and not abc#123

this is very strange, how can i still validate # sign and tell the user that # sign is not a valid username like i have been doing with any other special characters like = !@$...........

please advice.

thanks.

View user's profile Send private message

Reply with quote
Post  
I have tried the same code as you have given, its working fine.
 
I have uploaded below code at "http://pankajk.110mb.com/valid.php" you can check.


<?php
if(isset($_POST) && trim($_POST['name'])!='' ){
    $username = $_POST['name'];
    if( $username == "" ||  !preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $username) ){
        echo "User name cannot be blank or has special characters";
    } else {
        echo "Valid";
    }
}
?>
<form action="" method="post">
<input type="text" name="name" />
</form>

View user's profile Send private message Yahoo Messenger MSN Messenger

Reply with quote
Post  
thanks for replying. i have looked at the process and realised that i am using GET method.

following is the page sequence.

first page = register.php here a user enters a username and clicks on an image to find out
if the username is available or not. using a javascript function of onclick i am reading the

value entered in the form in javascript as
=============================================
var useri = document.registrationform.username
var valueofuseri = document.registrationform.username.value

var recui = /^\s{1,}$/g;

if ((useri.value==null) || (useri.value=="") || (useri.length=="") ||

(useri.value.search(recui))> -1)
{
alert("Please Enter a User Name")
return false
}

window.open("checkusernamei.php?theusernameis="+valueofuseri, "titleforavailabilityi",
"width=680,  height=275, status=1, scrollbars=1, resizeable=yes");

============================================

second page = checkusernamei.php = this file uses GET to read what was entered in the form.
============================================
$username = $_GET["theusernameis"];

if( $username == "" ||  !preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $username) )
{
echo "username is blank or has special characters";
}
============================================
the # sign is being ignored only if the image is clicked in order to check the username, if
the user enters abc#123 and clicks the submit button without clicking on the checkuser image button then my php validation for username shows an error message.

===========================================================
if( $username == "" ||  !preg_match("/^[a-z0-9]+(?:_[a-z0-9]+)?$/i", $username) )
{ echo "display error message for username"; }
===========================================================
now the problem is with clicking the image only and passing value using GET method how can i fix this problem.

please advice.

thanks.

View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
  



Google

FireFox! The PHP Forum Loans and Credit
Panama Web Design for Hire Free Insurance Quotes!
Web Hosting Advertise Here $10 a Month Designer Children
Never Pay Taxes Again HGH Domain name registration
Web Hosting and Dedicated Servers Insurance Affordable web-hosting


Web Design by PlatinumShore.com & Web Hosting by TradeWebHosting.com