Nandini Posted December 20, 2008 Share Posted December 20, 2008 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 Quote Link to comment Share on other sites More sharing options...
Nandini Posted December 20, 2008 Author Share Posted December 20, 2008 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> Quote Link to comment Share on other sites More sharing options...
Nandini Posted December 20, 2008 Author Share Posted December 20, 2008 My problem was solved by using "stripslashes" function . Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.