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 Link to comment https://forums.phpfreaks.com/topic/137792-solved-php-validation/ 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> Link to comment https://forums.phpfreaks.com/topic/137792-solved-php-validation/#findComment-720200 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 . Link to comment https://forums.phpfreaks.com/topic/137792-solved-php-validation/#findComment-720210 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.