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
https://forums.phpfreaks.com/topic/137792-solved-php-validation/
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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.