Username Validation With Php

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > PHP Programming

Username Validation With Php

rr77
A simple method of validation. This is good if you dont want spaces between caracters:

form.php

CODE
<FORM action="vali.php" method="post">
    <P>
    <LABEL for="user">User name: </LABEL>
    <INPUT type="text" id="user"><BR>
    <INPUT type="submit" value="Send">
    </P>
</FORM>



vali.php

CODE
<?php

$user =$_POST['user'];
$cuser=0;

for($i=0; $i<strlen($user); $i++)
  {
if ($user[$i]==" ")
    {
   $cuser=1;
    }
  }
  
if($cuser==1)
{
  echo "The user name have spaces";
}
else
{
   echo "The user name is correct";
}
?>


Notice from rvalkass:

Remember, all code must be placed in CODE BB tags. Thank you.

 

 

 


Reply

Stenno
CODE
<?
if(preg_match("/ /", $_POST['user'])){
  echo "The user name have spaces";
}else{
  echo "The user name is correct";
}
?>


This is exactly the same result in way shorter code. Besides to remove the spaces and to set the username and password to lowercase [when you have case-insensitive login system] and to prepare them for inserting to the database just use this code:

CODE
<?
$username = htmlentities(strtolower(trim($_POST['user'])),ENT_QUOTES);
$password  = htmlentities(strtolower(trim($_POST['password'])),ENT_QUOTES);
?>




Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : username validation php

  1. Php Email Validation - A PHP data validation class with many functions (1)
  2. Validation Script - Detecting Illegal Characters - preg_match to find illegal characters (0)
    I'm trying to validate a user's desired username for a registration page. I want to detect
    any illegal characters being used for a username. So far i have managed to include most execpt the
    '\', the '\' is used for escape and treating the preceding characters
    literally. I try to do '\\' but i get an error because it execects another
    character. CODE $ck_result = "Default"; $pattern =
    "/[!|@|#|$|%|^|&|*|(|)|_|\-|=|+|\||,|.|\/|;|:|\'
    ;|\"|&#...
  3. Php Check If Username Is Taken - (2)
    How would I go about making PHP check if a username is already registered? Thanks....
  4. Validation Error No Insert - (3)
    im having some trouble with this PHP Code: CODE while ($checking =
    mysql_fetch_array($check)){            $usr =
    $checking['loguser'];            $mail =
    $checking['logemail'];                                $error =
    "";                                            if ($mail == $email){  
                         $erroremail = "the email address you have chose is already taken";
                           $error = 1;                        }...
  5. Welcome <username> Help - I need some help (7)
    I already searched and I couldn't find a topic like this. But if there is I'm sorry. What I
    need help with is though. I need help having a "Welcome Guest" else "Welcome GodlyMoose". I want to
    put it on my index page also. I've looked everywhere and I cant find the code for it. I've
    tried making my own that failed. If I could use some help I would be very happy if someone could
    help me....



Looking for username, validation, php

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for username, validation, php

*MORE FROM TRAP17.COM*
advertisement



Username Validation With Php



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE