Bala Posted May 10, 2008 Share Posted May 10, 2008 can any one guide me to validate user in registration and display error at right hand side in red color for example "user name should contain 7 letter" when clicked submit button Link to comment https://forums.phpfreaks.com/topic/105058-user-validation-and-errors/ Share on other sites More sharing options...
BlueSkyIS Posted May 10, 2008 Share Posted May 10, 2008 can we see what you've got so far? Link to comment https://forums.phpfreaks.com/topic/105058-user-validation-and-errors/#findComment-537786 Share on other sites More sharing options...
Bala Posted May 10, 2008 Author Share Posted May 10, 2008 <?php /* this is guarunteed to work it is possible to use <? (short tags but this style works everywhere).*/ /*Only verify/validate form when it is submitted program name: form.php */ if(isset($_POST[submit])){ $error='';//initialize $error to blank if(trim($_POST[username])=='' || strlen(trim($_POST[username])) < 6 ||strlen(trim($_POST[username])) >12){ $error.="Please enter a username between 6 and 12 characters!<br />"; //concatenate the $error Message with a line break } if(trim($_POST[password])=='' || strlen(trim($_POST[password]))< 6){ $error.="Your password must be at least 6 characters in length!<br />";//concatenate more to $error } if(trim($_POST)==''){ $error.="An email address is required!<br />"; } else { if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST)) { $error="The e-mail you entered was not in the proper format!"; } } if($error==''){//Hmmmm no text is in $error so do something else, the page has verified and the email was valid // so uncomment the line below to send the user to your own success page or wherever (swap yourpage.php with your files location). //echo "script type=\"text/javascript\">window.location=\yourpage.php\"<script>"; } else{ echo "<span style=color:red>$error</span>"; } } ?> Link to comment https://forums.phpfreaks.com/topic/105058-user-validation-and-errors/#findComment-537789 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.