Jump to content

[SOLVED] php validation


Nandini

Recommended Posts

Hi all

 

I am so worrying about one problem.

i want validate username field with php

i want to allow only numbers, alphabets and periods(.) to username.

If i give '\' to username and click submit button

its giving error message like

"Only letters (a-z), numbers (0-9), and periods (.) are allowed."

 

till then fine.

But After i got error message my username value containg double \  (\\)

 

For example :

First i give peter\ into username field. The error message has displayed as above.  And username field shown as the value of peter\\. And i click submit again, error message has been displayed, username field shown as the value of peter\\\\.

Can anyone help me out. Its urgent. Here is my script.

<?

if($_POST)

{

if(!eregi("^[a-z0-9.]{4,16}$",$_POST['username']))

{

$errmsg='Only letters (a-z), numbers (0-9) and periods (.) are allowed.';

}

}

?>

 

<form method="post" action="">

<? echo $errmsg; ?>

<table border="0" width="100%" cellpadding="6" cellspacing="0">

<tr bgcolor="#e9f0f9"><td align="left">Username<font color="red">*</font></td>

<td align="left">

<input type="text" name="username" value="<? echo $_POST['username']; ?>">

</td></tr>

</table></form>

 

Can anyone help me

Link to comment
Share on other sites

Sorry i forgot to write submit button script. Here is my total script

 

<?

if($_POST)

{

if(!eregi("^[a-z0-9.]{4,16}$",$_POST['username']))

{

$errmsg='Only letters (a-z), numbers (0-9) and periods (.) are allowed.';

}

}

?>

 

<form method="post" action="">

<? echo $errmsg; ?>

<table border="0" width="100%" cellpadding="6" cellspacing="0">

<tr bgcolor="#e9f0f9"><td align="left">Username<font color="red">*</font></td>

<td align="left">

<input type="text" name="username" value="<? echo $_POST['username']; ?>">

</td></tr>

<tr><td colspan="2" align="center">

<input type="submit" name="submit" value="submit">

</td></tr>

</table></form>

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.