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.
24 2951
Cannot understand your problem?
What do you want your regex to accept and not accept?
Maybe we could help you create a new one.
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
Its not a problem with regexp.
It seems like you are submitting your username with ajax and not doing encodeURIComponent() to it before submitting.
Atli 5,058
Expert 4TB
Also, if you are submitting your usernames as GET variables, via the URL, the # character and anything that follows it will be parsed as an anchor name by the browser.
If that is the case, try the urlencode and urldecode functions.
Also, if you are submitting your usernames as GET variables, via the URL, the # character and anything that follows it will be parsed as an anchor name by the browser.
If that is the case, try the urlencode and urldecode functions.
But I thought the browser in itself always does urlencoding of the from elements before sending them by GET method (except when using Ajax). Don't you think so?
Try this example...
[HTML]<html>
<form action="page_doesnt_exist.htm">
<input name="param" value="">
<input type="submit" value="Check what's the url">
</form>
</html>[/HTML]
Just type in a value containing # in the field and click button to see what's the url. Isn't it already urlencoded?
I typed abc#xyz and got page_doesnt_exist.htm?param=abc%23xyz in the address bar when clicked on submit.
# got encoded to %23
Atli 5,058
Expert 4TB
But I thought the browser in itself always does urlencoding of the from elements before sending them by GET method (except when using Ajax). Don't you think so?
True. If you submit an actual <form> the browser should take care of this for you.
I was thinking more along the lines of putting them manually in the URL string.
Like if you had made a list of users and wanted each name to link to another script, passing along the username in the URL.
Could have chosen my words more carefully in my previous post. Sorry about that.
Where did you get the idea that this is to do with ajax or URLs?
Oh, because # marks a placement in the page and what comes after that is looked for in a div id.
I see.
But why submit it through GET?
Makes more sense for POST, right?
Where did you get the idea that this is to do with ajax or URLs?
Well, any variable (username in this case) can be posted by 4 ways (according to my knowledge).
1. Simple GET - # won't give any trouble as its already urlencoded by browser.
2. Simple POST - same here...
3. Ajax GET - # could cause a problem, as # in url is for anchors
4. Ajax Post - not sure about this one..
So I thought it could be case 3.
......because # marks a placement in the page and what comes after that is looked for in a div id.....
Sorry to disagree slightly here.
A destination anchor is not just, or only, a div. The destination anchors in HTML documents may be specified either by the A element (naming it with the name attribute), or by any other element (naming with the id attribute).
Ronald
True. If you submit an actual <form> the browser should take care of this for you.
I was thinking more along the lines of putting them manually in the URL string.
Like if you had made a list of users and wanted each name to link to another script, passing along the username in the URL.
Could have chosen my words more carefully in my previous post. Sorry about that.
Nothing to sorry about dude. :)
Yeah, in the case you said, one should do urlencode in PHP before sending the HTML to the browser.
Regards
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. follow 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="+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 using GET method how can i fix this problem.
please advice.
thanks.
- var valueofuseri=encodeURLComponent(document.registrationform.username.value);
Dude, this is what I suggested you in the other thread on same problem.
I guess you could not locate that thread in the long list of threads.
PS: Use [CODE] Tags.
Atli 5,058
Expert 4TB
Please do not double post your questions.
That only serves to cause confusion, waste the time of our fellow members and make us moderators mad!
And use [code] tags when posting your code examples.
Seeing as you have over 40 posts already, I expect you to know this by now.
Take a look at our Posting Guidelines if you haven't already.
I will not be happy if I need to repeat this warning!
I have merged the other thread into this one. Moderator
Heya, Runway.
What is the value of $username when the User inputs 'abc#123'?
Heya, Runway.
What is the value of $username when the User inputs 'abc#123'?
HEY YOUR BACK!!
*goes to cafe/lounce to see announcement*
I think he said the value is only "abc", the rest is truncated.
he needs url_encoding i believe, as every body here posted (some more than once)
PS: glad to see you back,
Dan
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.
Dear runway27,
When # goes in the URL, the text after the # is considered as anchor by the browser. When you are opening a new window with this code: - window.open("checkusernamei.php?theusernameis="+valueofuseri, "titleforavailabilityi", "width=680, height=275, status=1, scrollbars=1, resizeable=yes");
The URL is "checkusernamei.php?theusernameis="+valueofuse ri
And when your user name is abc#123, your URL becomes: checkusernamei.php?theusernameis=abc#123
So what happens is, #123 is considered as an anchor bookmark( see point 2 here) in the page.
With this, the value of your $_GET['theusernameis'] remains abc only.
To escape this, you should use encodeURIComponent in JavaScript.
So just change the second like of your JavaScript as - var valueofuseri = encodeURIComponent(document.registrationform.username.value)
If you want to encode it in PHP, after you click on the page and its opened in PHP, then that would be too late. As by that time your browser would have already considered text after # as anchor.
I apologize that I answered you twice on the same question but could not make you understand why is it so.
Hope you will get this this time.
Regards
Deja-vu.
Hasn't this been asked like 3 times (and answered)?
Deja-vu.
Hasn't this been asked like 3 times (and answered)?
I too think so... ;)
Atli 5,058
Expert 4TB
Deja-vu.
Hasn't this been asked like 3 times (and answered)?
Indeed. This will be the second time I merge a duplicate thread with the original thread.
runway27, you have been warned twice before about double-posting and using [code] tags, and you just keep ignoring us.
This behavior is not acceptable and has just earned you a 1 week ban.
I suggest you take that time to familiarize yourself with the Posting Guidelines.
The next time you ignore the guidelines, the ban will be permanent. Moderator
This behavior is not acceptable and has just earned you a 1 week ban.
aww.. this is gonna be harsh. But rules are rules.
I didn't get one thing though... he never replied in the already started thread. He got many replies, but he didn't give a damn.
What did he think about us?.....
Sorry to disagree slightly here.
A destination anchor is not just, or only, a div. The destination anchors in HTML documents may be specified either by the A element (naming it with the name attribute), or by any other element (naming with the id attribute).
Ronald
I wasn't being specific to only divs.
aww.. this is gonna be harsh. But rules are rules.
I didn't get one thing though... he never replied in the already started thread. He got many replies, but he didn't give a damn.
What did he think about us?.....
I just don't understand some people..
Could it've been a bot?
I just don't understand some people..
Could it've been a bot?
LOL!... and that bot has just got to ask a technical question in bytes?... not a good utility bot.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ralph Freshour |
last post by:
I'm looking in my PHP book but still figure out the best way to
validate that certain characters are contained in a string - for
example, when a user enters a username, I want to limit the...
|
by: Ramnadh Nalluri |
last post by:
Hi,
I am creating DirectoryEntry in the C#.Net by taking the constructor
DirectoryEntry("LDAP://<Domain>",<UserName>,<Pwd>,AuthenticationType.Sec
ure)
and creating the DirectoryEntry. But i...
|
by: Patrick.O.Ige |
last post by:
I have a code below.(It validates against a SQL DB(login page).thats is
giving me an error!
When i try to use :- Session = dr.ToString();
To catch the username so as to redirect the user logged in...
|
by: Patrick.O.Ige |
last post by:
I have a problem with the code below:-
When i use a username for example dog for the first time it works but later
when i use cat for example it keeps showing
Hello:- Dog..
It keeps DOG in the...
|
by: Patrick.O.Ige |
last post by:
Is it possible to execute a query or do some validation before loading a page..
I have a survey page and i want to validate users before loading the page.
I have done it in the page_load.
But the...
|
by: Steve |
last post by:
I have created a tableadaptor in VWD called
"MemberUsernameTableAdaptor" with a "GetUsername()" method.
The method requires the @username parameter and will then try matching
it up in the username...
|
by: ryan |
last post by:
i am storing a usernames and passwords in a table called Users.
I present a login form to the user when my application starts up
(VB.NET, .NET CF, Windows Mobile 5)
The user chooses a username...
|
by: Sudhakar |
last post by:
i have used the following code to validate the username it is working
fine
=============================================
if( $username == "" || !preg_match("/^+(?:_+)?$/i",
$username) )
{...
|
by: phpmagesh |
last post by:
Hi
I am creating login page with validation.
i have index.php page with login box, for validating this login detail i m redirecting to login_validate.php.
Login_validate.php file code:
...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |