Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
validating # sign in php
Old 05-29-2008, 03:46 PM validating # sign in php
Ultra Talker

Posts: 254
Trades: 0
my question is about validation using php. i am validating a username which a user would

enter and clicks on a image to find if that username is available. example if a user enters

abc#123 php file is reading this value as abc ONLY which i do not want instead the php file

should read as abc#123. following is the sequence of pages. please advice the solution.

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="+va lueofuseri, "titleforavailabilityi",

"width=680, height=275, status=1, scrollbars=1, resizeable=yes");

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

i have used a alert message in javascript to display the value, javascript is able to

capture all the characters entered which is abc#123

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 the value to checkusernamei.php

using GET method
i have also used an echo statement in checkusernamei.php as
echo "value of username is ". $username; = this displays abc and not abc#123

how can i fix this problem wherein checkusernamei.php will be able to read abc#123. also in

this checkusernamei.php file i have a select query which will read if the username already

exists in the table. presently as checkusernamei.php is reading abc ONLY the select query is

also passing abc and not abc#123

$select = "Select username from table where username = '$username'";

please advice.

thanks.
sudhakararaog is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-29-2008, 04:31 PM Re: validating # sign in php
Veter's Avatar
Super Talker

Posts: 147
Trades: 0
var valueofuseri = document.registrationform.username.value
change to
var valueofuseri = escape(document.registrationform.username.value)
__________________
-=
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
=-
Veter is offline
Reply With Quote
View Public Profile Visit Veter's homepage!
 
Old 05-29-2008, 04:49 PM Re: validating # sign in php
Ultra Talker

Posts: 254
Trades: 0
thanks for replying. as you suggested i used the escape() in javascript as follows

var valueofuseri = escape(document.registrationform.username.value)

and in php i read this value as

$username = $_GET['theusernameis'];


so for example if i enter abcd#1234 javascript alert reads it as "abcd%231234"
and the php file reads it as abcd#1234

and based on my php validation # sign is not allowed and an message is being displayed that # sign is not allowed in the username and this is what i wanted.

to confirm is this working fine.

please advice.
sudhakararaog is offline
Reply With Quote
View Public Profile
 
Old 07-17-2008, 10:27 AM Re: validating # sign in php
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
the # is used for a client side anchor, so will NOT be available in serverside code.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to validating # sign in php
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.78487 seconds with 12 queries