Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if($_SERVER["REQUEST_METHOD"] == "POST"){
- $fullName = test_input($_POST['fullname']);
- $Email = test_input($_POST['email']);
- $userName = test_input($_POST['username']);
- $passWord = test_input(sha1($_POST['password']));
- echo $fullName . "<br />" . $Email . "<br />" . $userName . "<br />" . $passWord . "<br />";
- if(filter_var($Email,FILTER_VALIDATE_EMAIL)){
- echo 'your email is valid ' . '<br />';
- }else{
- echo 'your email is not valid : try again' . '<br />';
- }
- if(preg_match('/[\'^£$%&*()}{@#~?><>,|=_+¬-]/',$fullName)){
- // or if(!preg_match('/^[0-9a-zA-Z ]+$/',$fullName))
- echo 'bad full name input ';
- }
- else{
- echo 'good full name input ';
- }
- }
- function test_input($inputField){
- $inputField = htmlspecialchars(stripcslashes(strip_tags($inputField)));
- return $inputField;
- }
- ?>
- <html>
- <head>
- <meta charset='UTF-8'>
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
- </head>
- <body>
- <form action="<?php htmlspecialchars($_SERVER['PHP_SELF']) ?>" method="POST">
- <h1>CodeJs : Input Validation </h1>
- <div class="form-group">
- <label>Full Name:</label>
- <input type="text" class="form-control" name='fullname'>
- </div>
- <div class="form-group">
- <label>Email address:</label>
- <input type="text" class="form-control" name='email'>
- </div>
- <div class="form-group">
- <label>Username :</label>
- <input type="text" class="form-control" name='username'>
- </div>
- <div class="form-group">
- <label>Password:</label>
- <input type="text" class="form-control" name='password'>
- </div>
- <button type="submit" class="btn btn-default">Submit</button>
- </form>
- <style>form{ width: 400px; margin-left: 350px; }</style>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
- <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment